How do I get a GKPlayer's status from Game Center?

那年仲夏 提交于 2019-12-23 16:11:19

问题


When I get a GKLocalPlayer or use loadPlayersForIdentifiers:identifiers withCompletionHandler: to get a list or individual GKPlayer aliases, the GKPlayer object when logged, looks something like this:

2010-09-23 10:39:01.759 Cee-lo[76500:207] Players loaded by identity: (
    "<GKPlayer 0x84125a0>(playerID: G:1234567890, alias: typeonetester1, status: Adding test friends., rid:(null))",
    "<GKPlayer 0x8412530>(playerID: G:1234567890, alias: typeonetester2, status: Adding Game Center to app, rid:(null))"
)

My question is, how do I get the status from this object, and what exactly is the type of this object? There is no "rid" or "status" property in the GKPlayer class, so when I do something like:

GKPlayer *player = [self.friends objectAtIndex:row];

cell.nameLabel.text = player.alias;
cell.statusLabel.text = player.status;

I get a "Request for member 'status' in something not a structure or union" error.


回答1:


Answered by an Apple engineer:

The players' status is not an accessible property. This was changed in one of the 4.1 betas & is noted in the 4.1 relnotes.




回答2:


NSString *desc = player.description;
NSRange range = [desc rangeOfString:@"status:"];
NSString *status = [[desc substringFromIndex:NSMaxRange(range)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];


来源:https://stackoverflow.com/questions/3781195/how-do-i-get-a-gkplayers-status-from-game-center

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!