2011-01-19 2 views
1

연결이없는 경우 나중에 점수를 저장하고 업로드하는 방법은 무엇입니까?GameKit으로 점수 업로드

NSData *archivedScore = [NSKeyedArchiver archivedDataWithRootObject:[NSData dataWithBytes:&score length:sizeof(score)]]; 

그때 NSUSerDefaults에있는 NSData 객체를 저장 : WWDC 세션에서는 어떤 연결을 사용할 수없는 경우 다음 코드를 사용했다. 하지만 int score 값을보고에서 다시 얻으려면 어떻게해야합니까?

감사

+0

당신은 정수를 직렬화하고 다시 래퍼를 직렬화? 다시 직렬화하면 더 이상 성공할 수 있으므로 탈출 할 수 없습니다! ;) – JustSid

답변

1

(Archives and Serializations Programming Guide에서) 사용 NSKeyedUnarchiver

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