Game Center をアプリに実装しようとしていますが、以下のコードがスコアを報告しています。
私は解決策を達成しようとしています。プレイヤーが認証されていない場合、scoreReporter ブロックを介してスコアを scoreDictionary に保存する必要があります。ただし、プレーヤーが認証されていない場合、「If (error != nil)」ステートメントにヒットすることはありません。
実際のところ、ブロック全体を通過します。ローカル プレイヤーが認証されると、ブロックが実行されます。
Game Center とブロックの両方を詳細に調べるのはこれが初めてなので、ここで少し迷っています。
私が達成したいことは、上記のとおりです。
ターゲットとして 5.1 を使用します。
-(void)reportScore:(int64_t)score forCategory:(NSString*)category {
NSLog(@"reportScore: %lli", score);
NSLog(@"category: %@",category);
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];
scoreReporter.value = score;
NSLog(@"scoreReporter: %@", scoreReporter);
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
NSLog(@"Execute the scoreReporter the block");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *scoreFilePath = [NSString stringWithFormat:@"%@/scores.plist",[paths
objectAtIndex:0]];
NSMutableDictionary *scoreDictionary=[NSMutableDictionary
dictionaryWithContentsOfFile:scoreFilePath];
if (error != nil)
{
//There was an error so we need to save the score locally and resubmit later
NSLog(@"Saving score for later");
[scoreDictionary setValue:scoreReporter forKey:[NSDate date]];
[scoreDictionary writeToFile:scoreFilePath atomically:YES];
}
}];
}
プレーヤーが認証されていない場合の NSLog 出力:
reportScore: 80
category: com.xxxxxx.yyyyyyyHighScore
scoreReporter: <GKScore: 0xab611b0>player:(null) rank:0 date:2012-12-19 11:18:04 +0000 value:80 formattedValue:(null) context:0x0
プレーヤーが認証されたときの NSLog 出力:
reportScore: 60
category: com.xxxxxx.yyyyyyyHighScore
scoreReporter: <GKScore: 0x964ce30>player:G:280817155 rank:0 date:2012-12-19 11:27:45 +0000 value:60 formattedValue:(null) context:0x0
Execute the scoreReporter the block