2015-12-18 45 views
0

我一直在使用DaRkDOG簡易遊戲中心代碼(非常有用!),並添加了一個額外的類(如下所示)以發送評分「挑戰朋友」請求。遊戲中心挑戰朋友發送的應用程序崩潰

public class func challengeFriendRequest(leaderboard: String, scoreValue : Int64, players: [GKPlayer]) { 

    guard EGC.isPlayerIdentified else { 
     EGCError.NotLogin.errorCall() 
     return 
    } 

    guard EGC.isConnectedToNetwork else { 
     EGCError.NoConnection.errorCall() 
     return 
    } 

    do { 
     let message : String? = "Try and beat this!" 
     let score = GKScore(leaderboardIdentifier: leaderboard) 
     score.value = scoreValue 

     let delegatVC = try EGC.sharedInstance.getDelegate() 
     var delegateParent:UIViewController? = delegatVC.parentViewController 
     if delegateParent == nil { 
      delegateParent = delegatVC 
     } 

     let controllerGKChallenge = score.challengeComposeControllerWithMessage(message, players: players, completionHandler: { (challengeVC, didChallenge, playersChallenged) -> Void in 

      if didChallenge { 
       print("\(playersChallenged!.count) players challenged") 
      } 
      delegateParent!.dismissViewControllerAnimated(true, completion: nil) 
     }) 

      delegateParent!.presentViewController(controllerGKChallenge, animated: true, completion: nil) 

    } catch EGCError.NoDelegate { 
     EGCError.NoDelegate.errorCall() 

    } catch { 
     fatalError("Dont work\(error)") 
    } 
} 

遊戲中心「挑戰之友」彈出窗口出現填充正確的朋友和消息。我可以取消通話並控制返回到應用程序。但是,如果我用下面的錯誤發送的挑戰應用程序崩潰:

thread 1 exc_breakpoint (code=exc_arm_breakpoint, subcode = 0xe7ffdefe).

在堆棧的頂部的錯誤提示數組力鑄的問題:

"0_arrayForceCast A,B> ([A]) -> [B]".

我覺得這可能有一些在鑄造通話中使用的GKPlayers陣列,但我無法弄清楚問題所在。

任何指向正確方向的指針都會很棒。

我正在測試我的應用程序在iOS 9.1部署目標上的iPad 2和iPhone 5s。

回答

0

儘管沒有直接解決問題,但我已經能夠使用已棄用的challengeComposeControllerWithPlayers和來自另一個帖子(fatal error: can't unsafeBitCast between types of different sizes (using gamekit))的一些幫助來複制並解決問題。

它似乎是與GKPlayers類型鑄造問題。以下作品按照上面張貼提供的建議:

if let players = players as [GKPlayer]? { 
      let playerIDs = players.map { $0 .playerID! } as [String]? 
      let controllerGKChallenge = score.challengeComposeControllerWithPlayers(playerIDs, message: message, completionHandler: { (challengeVC, didChallenge, playersChallenged) -> Void in 
       if completion != nil { completion!(isShow:true) } 
       if didChallenge { 
        print("\(playersChallenged!.count) players challenged") 
       } 
       delegateParent!.dismissViewControllerAnimated(true, completion: nil) 
      }) 
      delegateParent!.presentViewController(controllerGKChallenge!, animated: true, completion: nil) 
     } 

我已經嘗試了許多不同的鑄件challengeComposeControllerWithMessage但至今我無法來解決問題。

任何幫助將不勝感激。

相關問題