开发者

Uploading scores with GameKit

开发者 https://www.devze.com 2023-02-05 06:18 出处:网络
How do I save and upload scores later if there is no connection available? In a WWDC session it says to use the following code if no connection is available:

How do I save and upload scores later if there is no connection available? In a WWDC session it says to use the following code if no connection is available:

NSData *archivedScore = [NSKeyedArchiver archivedDataWithRootObject:[NSData dataWithBytes:&score length:sizeof(score)]];
开发者_运维技巧

I then save the NSData object to NSUSerDefaults. But how do I get an int score value back from that to report?

Thanks


Use NSKeyedUnarchiver (from Archives and Serializations Programming Guide)

int score = 42;
NSData *archivedScore = [NSKeyedArchiver archivedDataWithRootObject:[NSData dataWithBytes:&score length:sizeof(score)]];
int *scorePtr = [[NSKeyedUnarchiver unarchiveObjectWithData:archivedScore] bytes];
NSLog(@"score = %d", *scorePtr); // Output: score = 42
0

精彩评论

暂无评论...
验证码 换一张
取 消