私はターン制のゲームを開発することを計画しており、Game Centerと通信し、マッハデータを送受信する方法を理解しようとしています。私はそれについて読み、これを数日間テストしましたが、計画どおりに機能させることができません。
以下のコードで私がやろうとしているのは、マッハデータを保存して読み取ることができるようにすることだけです。私はターンに2つのサンドボックスゲームセンターアカウントを使用しています。
ターンは「endTurn」ボタンを押して同じデータを送信しています。実行するたびに、実際のユーザーが認証され、アプリが正しくセットアップされます(私は信じています)。
これは、私が述べたことをテストする以外の目的のないテストアプリです。以下は、一致データの処理に使用するコードです。
私が間違っているかもしれないことについてのアイデアやヒントを本当にいただければ幸いです。本格的なテストを開始する前に、同様の質問を投稿しましたが、この問題は解決しませんでした。https://stackoverflow.com/questions/14447392/start-gamecenter-turn-based-match-and-initiate-match-data-for -非常に最初のタイミング。
私も参加者を捕まえようとしましたが、成功しませんでした。これは、completionhandlerを処理するときに問題になる可能性があります。
-(IBAction)endTurn:(id)sender {
[_gameDictionary setObject:@"The Object" forKey:@"The Key"];
NSLog(@"_gameDictionary: %@", _gameDictionary);
NSData *data = [NSPropertyListSerialization dataFromPropertyList:_gameDictionary format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
GKTurnBasedParticipant *nextPlayer;
if (_match.currentParticipant == [_match.participants objectAtIndex:0]) {
nextPlayer = [[_match participants] lastObject];
} else {
nextPlayer = [[_match participants]objectAtIndex:0];
}
NSLog(@"_match.currentParticipant: %@", _match.currentParticipant);
[self.match endTurnWithNextParticipant:nextPlayer matchData:data completionHandler:^(NSError *error) {
if (error) {
NSLog(@"An error occured updating turn: %@", [error localizedDescription]);
}
[self.navigationController popViewControllerAnimated:YES];
}];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
_gameDictionary = [[NSMutableDictionary alloc]init];
[self.match loadMatchDataWithCompletionHandler:^(NSData *matchData, NSError *error) {
NSDictionary *myDict = [NSPropertyListSerialization propertyListFromData:_match.matchData mutabilityOption:NSPropertyListImmutable format:nil errorDescription:nil];
[_gameDictionary addEntriesFromDictionary: myDict];
if (error) {
NSLog(@"loadMatchData - %@", [error localizedDescription]);
}
}];
NSLog(@"_gameDictionary: %@", _gameDictionary);
}
出力:
"gk-cdx" = "17.173.254.218:4398";
"gk-commnat-cohort" = "17.173.254.220:16386";
"gk-commnat-main0" = "17.173.254.219:16384";
"gk-commnat-main1" = "17.173.254.219:16385";
}
2013-02-11 22:44:11.707 GC_test1[8791:14f03] _gameDictionary: {
}
2013-02-11 22:44:13.894 GC_test1[8791:14f03] _gameDictionary: {
The Object = The Key;
}
2013-02-11 22:44:13.894 GC_test1[8791:14f03] _match.currentParticipant: (null)