मुझे यह आज रात मेरे खेल पर काम कर रहा है। संचार चैनल सेटअप प्राप्त करने के लिए आपको और अधिक बातचीत करने की आवश्यकता है। आविष्कार में लौटा प्रारंभिक मैच आमंत्रित करने के लिए आमंत्रित करने का इंतजार कर रहा है ... यहां केवल दो खिलाड़ियों के साथ मेरी प्रक्रिया है। मेरे संचार स्पिन-अप प्रदर्शन करने वाले सभी चरण यहां दिए गए हैं। जाहिर है, कोई वास्तविक त्रुटि हैंडलिंग यहाँ शामिल:
सबसे पहले, सही प्रमाणीकरण सेट inviteHandler के बाद अपने खिलाड़ी के लिए प्रमाणीकृत
दूसरा,। कुछ इस तरह:
[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite* acceptedInvite, NSArray *playersToInvite)
{
if(acceptedInvite != nil)
{
// Get a match for the invite we obtained...
[[GKMatchmaker sharedMatchmaker] matchForInvite:acceptedInvite completionHandler:^(GKMatch *match, NSError *error)
{
if(match != nil)
{
[self disconnectMatch];
// Record the new match...
self.MM_gameCenterCurrentMatch = match;
self.MM_gameCenterCurrentMatch.delegate = self;
}
else if(error != nil)
{
NSLog(@"ERROR: From matchForInvite: %@", [error description]);
}
else
{
NSLog(@"ERROR: Unexpected return from matchForInvite...");
}
}];
}
};
तीसरा, दोस्त playerIds (नहीं उर्फ) की अपनी सूची प्राप्त करें।
// Initialize the match request - Just targeting iOS 6 for now...
GKMatchRequest* request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = [NSArray arrayWithObject:player.playerID];
request.inviteMessage = @"Let's play!";
// This gets called when somebody accepts
request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse response)
{
if (response == GKInviteeResponseAccepted)
{
//NSLog(@"DEBUG: Player Accepted: %@", playerID);
// Tell the infrastructure we are don matching and will start using the match
[[GKMatchmaker sharedMatchmaker] finishMatchmakingForMatch:self.MM_gameCenterCurrentMatch];
}
};
पांचवां, findMatchForRequest कॉल करने के लिए अनुरोध का उपयोग करें:: withCompletionHandler: कुछ इस तरह ...
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch* match, NSError *error) {
if (error)
{
NSLog(@"ERROR: Error makeMatch: %@", [error description]);
[self disconnectMatch];
}
else if (match != nil)
{
// Record the new match and set me up as the delegate...
self.MM_gameCenterCurrentMatch = match;
self.MM_gameCenterCurrentMatch.delegate = self;
// There will be no players until the players accept...
}
}];
चौथा, सेटअप इस तरह से अपनी GKMatchRequest कुछ ... मैं केवल एक दोस्त को आमंत्रित कर रहा हूँ
छठा, यह दूसरे खिलाड़ी से अनुरोध भेजता है और यदि वे दूसरे चरण से "आमंत्रण हैंडलर" को स्वीकार करते हैं।
सातवां, दूसरे चरण से "आमंत्रण हैंडलर" जीकेइन्वाइट के लिए मैच प्राप्त करता है!
आठवां, चौथे चरण से "आमंत्रण रिस्पॉन्स हैंडलर" कहलाता है जिसने मैच समाप्त किया!
नौवां, मैच के अंतिम रूप को संभालने के लिए जीकेमैचडिलेगेट से किया गया चेंजस्टेट बनाएं।कुछ इस तरह:
- (void) sendMessage:(NSString*)action toPlayersInMatch:(NSArray*) playerIds{
NSError* err = nil;
if (![self.MM_gameCenterCurrentMatch sendData:[action dataUsingEncoding:NSUTF8StringEncoding] toPlayers:playerIds withDataMode:GKMatchSendDataReliable error:&err])
{
if (err != nil)
{
NSLog(@"ERROR: Could not send action to players (%@): %@ (%d) - '%@'" ,[playersInMatch componentsJoinedByString:@","],[err localizedDescription],[err code], action);
}
else
{
NSLog(@"ERROR: Could not send action to players (%@): null error - '%@'",[playersInMatch componentsJoinedByString:@","], action);
}
}
else
{
NSLog(@"DEBUG: Message sent to players (%@) - '%@'",[playersInMatch componentsJoinedByString:@","], action);
}}
ग्यारहवीं, इस तरह की एक didReceiveData GKMatchDelegate से कुछ बनाना:
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state{
switch (state)
{
case GKPlayerStateConnected:
// Handle a new player connection.
break;
case GKPlayerStateDisconnected:
// A player just disconnected.
break;
}
if (!self.matchStarted && match.expectedPlayerCount == 0)
{
self.matchStarted = YES;
// Handle initial match negotiation.
if (self.iAmHost && !self.sentInitialResponse)
{
self.sentInitialResponse = true;
// Send a hello log entry
[self sendMessage: [NSString stringWithFormat:@"Message from friend, 'Hello, thanks for accepting, you have connected with %@'", self.MM_gameCenterLocalPlayer.alias] toPlayersInMatch: [NSArray arrayWithObject:playerID]];
}
}}
दसवीं, यहाँ मेरी SendMessage है
- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID{
NSString* actionString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
// Send the initial response after we got the initial send from the
// invitee...
if (!self.iAmHost &&!self.sentInitialResponse)
{
self.sentInitialResponse = true;
// Send a hello log entry
[self sendMessage: [NSString stringWithFormat:@"Message from friend, 'Hello, thanks for inviting, you have connected with %@'", self.MM_gameCenterLocalPlayer.alias] toPlayersInMatch: [NSArray arrayWithObject:playerID]];
}
// Execute the action we were sent...
NSLog(actionString);}
बारहवीं ... खैर अब आप संचार चैनल ऊपर और चल रहे हैं ... जो भी आप चाहते हैं ...
आप कैसे शुरू किया BrowsingForNearbyPla yersWithReachable हैंडलर काम करने के लिए? मुझे इससे कोई कॉलबैक नहीं मिला ?? – bobmoff