ios - What would you prefer in order to deal with Game-Center's invite friends? -
i've been trying implement invites gkturnbasedmatch. i've gone through documentation , web portals.
here i'm doing. firstly, i'm registering gklocalplayerlistener
follows.
if(!gklocalplayer.localplayer().isauthenticated) { authenticateplayer { (auth) in weak var weakself = self weak var weakplayer = gklocalplayer.localplayer() if(auth){ weakplayer?.register(weakself!) self.suthentication = true; //self.removeallmatches() //self.retrievefriends() } else{ print("failed in authentication") self.suthentication = false; } } } else { // authenticated gklocalplayer.localplayer().register(self) localplayer = gklocalplayer.localplayer() //removeallmatches() }
now can reach listener's default methods. default way of invites, it's possible test invite friends. , default process send initialised match invitee listener's method.
func player(_ player: gkplayer, receivedturneventfor match: gkturnbasedmatch, didbecomeactive: bool) { .... }
on receiver side, when invitee taps on match notification, method called, showing invitee second player of match.
func player(_ player: gkplayer, didaccept invite: gkinvite) { toplabel.text = "recieved 5" print("did accept invite:") }
when same process being done following criterion, error arose nil match object.
func retrievefriends() { let lp = gklocalplayer.localplayer() if lp.isauthenticated { lp.loadfriendplayers(completionhandler: { (pl, e) in if e == nil { print(pl) let req = gkmatchrequest() req.minplayers = 2; req.maxplayers = 2; req.invitemessage = "1234567788899 "; req.recipients = pl; gkmatchmaker.shared().findmatch(for: req, withcompletionhandler: { (m, e) in if e == nil { print(m?.players) } else { print(e?.localizeddescription) } if m == nil { print(m) } else { print(m) } }) } }) } }
now i've tested code, show match object nil , error printed, later invitee's device receive same matchmaking notification.
in nutshell, need adoptive description related query. isn't @ comprehensive task, in spite of, need selective options based on experience , practical knowledge of game centre documentation.
thank you.
Comments
Post a Comment