2
votes

I am doing a sprite kit Game. I have a problem with Game Center: how i authenticate player? in AppDelegate.swift i have this code:

     func authenticateLocalPlayer()
     {


     var localPlayer = getLocalPlayer() // see GKLocalPlayerHack.h
    localPlayer.authenticateHandler =
        {(viewController : NSViewController?, error : NSError?) -> Void in
            if viewController != nil
            {
                self.presentViewController(viewController!, animated:true, completion: nil)

                        }

but i get this error:

Value of type 'AppDelegate' has no member 'presentViewController'

on this line:

 self.presentViewController(viewController!, animated:true, completion: nil)

How can i solve this problem?

2
you are using self.presentViewController at wrong place self.presentViewController function relative to UIViewController so write your function inside a UIViewControllerdragoneye
The problem is that i have not a UIViewController...i have a SpriteKit Game without view Controllers....i need only to authenticate Player with Game Center at startup...Swift1

2 Answers

1
votes

I think you need to use something like this. I am not 100% sure what you set for the parentWindow bit, my OSX knowledge is limited.

let dialogController = GKDialogController.shared()
dialogController.parentWindow = yourWindow // not exactly sure what you need to set here
dialogController.presentViewController(viewController)

Implementing GameKit.framework on OSX, cannot authenticate localPlayer

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/GameKit_Guide/DisplayingGameCenterUserInterfaceElements/DisplayingGameCenterUserInterfaceElements.html

Hope this helps.

0
votes

I suggest to use a viewcontroller ;-) Take a look at my answer here I won't copy it one to one.

Adding Game Center Leaderboard