2017-06-17 30 views
0

在我的iOS回合制的比赛,我想接收通知,并获得iOS版回合制的比赛,推送通知不工作,GKTurnBasedEventListener功能不叫

public func player(_ player: GKPlayer, receivedTurnEventFor match: GKTurnBasedMatch, didBecomeActive: Bool) 

被调用,没有成功。

注册我的视图模型为本地玩家

GKLocalPlayer.localPlayer().register(self) 

,我会想到火其他球员执行

func endTurn(withNextParticipants nextParticipants: [GKTurnBasedParticipant], turnTimeout timeout: TimeInterval, match matchData: Data, completionHandler: ((Error?) -> Swift.Void)? = nil) 

,但没有成功之后。

如果我强制重新加载matchData,那么我会得到刚刚提交的第二位玩家的数据。所以endTurn工作正常。

有什么我做错了吗?

更新: 因此,我创建了一个新项目,将所有文件复制到 中,但只启用了Game Center的功能。

当开发工作完美时,我有两个设备连接(不同的苹果ID)。通知正在工作,Turnbasedlistener正在开枪。

只要我发布它的内部测试它停止工作!

+0

你有没有仔细检查了您的应用程序允许下的“设置”推送通知?如果用户决定不启用推送通知,则不会调用“receivedTurnEventFor”。 –

+0

是的,我做了,允许推送通知已启用(徽章) – tallis

+0

因此,我创建了一个新项目,将所有文件复制过来,只启用了Game Center的功能。当开发工作完美时,我有两个设备连接(具有不同的苹果ID)。通知正在工作,Turnbasedlistener正在开枪。只要我释放它进行内部测试,它就停止工作了! – tallis

回答

0

我有非常类似的问题。我的解决方案是在等待轮到我时手动重新检查我的状态。 首先,我定义的全局变量var gcBugTimer: Timer

endTurn(withNextParticipants:turnTimeOut:match:completionHan‌​dler:)完成处理:

let interval = 5.0 
self.gcBugTimer = Timer.scheduledTimer(timeInterval: interval, target: self, selector: #selector(self.isMatchActive), userInfo: nil, repeats: true) 
self.gcBugTimer.tolerance = 1.0 

以上代码也应该在的情况下,当一个球员被joying在一个翻开新的比赛和其他玩家进行调用。

然后计时器方法:

func isMatchActive() { 
    // currentMatch - global variable contains information about current match 
    GKTurnBasedMatch.load(withID: currentMatch.matchID!) { (match, error) in 
    if match != nil { 
     let participant = match?.currentParticipant 
     let localPlayer = GKLocalPlayer.localPlayer() 
     if localPlayer.playerID == participant?.player?.playerID { 
     self.player(localPlayer, receivedTurnEventFor: match!, didBecomeActive: false) 
     } 
    } else { 
     print(error?.localizedDescription ?? "") 
    } 
    } 
} 

,然后加在player(_:receivedTurnEventFor:didBecomeActive)最开始下面的代码:

if gcBugTimer != nil && gcBugTimer.isValid { 
    gcBugTimer.invalidate() 
}