Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 47 additions & 8 deletions RNGameCenter/ios/RNGameCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,58 @@ - (dispatch_queue_t)methodQueue{
}

@try {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
NSDictionary* user = @{
@"alias":localPlayer.alias,
@"displayName":localPlayer.displayName,
@"playerID":localPlayer.playerID,
@"alias":localPlayer.alias
};
resolve(user);

[[GKLocalPlayer localPlayer] generateIdentityVerificationSignatureWithCompletionHandler:^(NSURL *publicKeyUrl, NSData *signature, NSData *salt, uint64_t timestamp, NSError *error) {
NSDictionary* user = @{
@"playerId":[GKLocalPlayer localPlayer].playerID,
@"alias":[GKLocalPlayer localPlayer].alias,
@"displayName":[GKLocalPlayer localPlayer].displayName,
@"publicKeyUrl":[publicKeyUrl absoluteString],
@"signature":[self base64forData:signature],
@"salt":[self base64forData:salt],
@"timestamp":@(timestamp),
@"bundleId": [[NSBundle mainBundle] bundleIdentifier]
};
resolve(user);
}];

}@catch (NSError * e) {
reject(@"Error",@"Error getting user.", e);
}
}

- (NSString*)base64forData:(NSData*)theData {
const uint8_t* input = (const uint8_t*)[theData bytes];
NSInteger length = [theData length];

static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t* output = (uint8_t*)data.mutableBytes;

NSInteger i;
for (i=0; i < length; i += 3) {
NSInteger value = 0;
NSInteger j;
for (j = i; j < (i + 3); j++) {
value <<= 8;

if (j < length) {
value |= (0xFF & input[j]);
}
}

NSInteger theIndex = (i / 3) * 4;
output[theIndex + 0] = table[(value >> 18) & 0x3F];
output[theIndex + 1] = table[(value >> 12) & 0x3F];
output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}

return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
}


/* --------------loadLeaderboardPlayers--------------
//let leaderboardIdentifier="high_scores"
// let achievementIdentifier="pro_award"
Expand Down