gamecenterを使ってログイン機能を実装したいです。
一度ビルドしたらログイン画面が出てくるようになったのに、急にautherication:faildとプリントされるようになってしまいました。
原因としては何が考えられるでしょうか。
コードは以下の通りです。どなたかご教授、よろしくお願いします。
appdelegate.swift
swift
1 2 var window: UIWindow? 3 4 5 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 6 // Override point for customization after application launch. 7 8 window = UIWindow(frame: UIScreen.main.bounds) 9 if let window = window{ 10 window.backgroundColor = UIColor.white 11 window.rootViewController = TopViewController() 12 window.makeKeyAndVisible() 13 } 14 // GameCenter Auto Login 15 if let presentView = window?.rootViewController { 16 let targetViewController = presentView 17 GKLocalPlayerUtil.login(target: targetViewController) 18 } 19 return true 20 21 }
GKLocalPlayerUtil.swift
swift
1struct GKLocalPlayerUtil { 2 static var localPlayer:GKLocalPlayer = GKLocalPlayer(); 3 4 static func login(target: UIViewController){ 5 self.localPlayer = GKLocalPlayer.localPlayer() 6 self.localPlayer.authenticateHandler = {(viewController, error) -> Void in 7 if ((viewController) != nil) { 8 print("LoginCheck: Failed - LoginPageOpen") 9 target.present(viewController!, animated: true, completion: nil); 10 }else{ 11 print("LoginCheck: Success") 12 if (error == nil){ 13 print("LoginAuthentication: Success") 14 }else{ 15 print("LoginAuthentication: Failed") 16 } 17 } 18 } 19 } 20}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/05 07:38
2018/04/05 07:42