질문 제목에 authPlayerWithCompletionHandler가 거의 사용되지 않으므로 authenticateHandler는 어떻게 사용합니까?authPlayerWithCompletionHandler 어떻게하면 authenticateHandler를 사용할 수 있습니까?
답변
setAuthenticateHandler는 아이폰 OS 6, authenticateWithCompletionHandler 여전히 아래에서 iOS 5 및 사용해야합니다 새로운 기능입니다.
또한 presentViewController : animated : completion :에 대한 완료 핸들러를 제공하는 것은 실제로 완료되지 않았지만 게임 센터보기가 표시된 후에 완료 핸들러가 호출되기 때문에 실제로 필요하지 않습니다. 하지 실제 장치에서 - - 6.0 시뮬레이터에서만 아이폰 OS 4.3, 아이폰 OS 5.1, iOS에서 테스트
참고 :
여기 내 솔루션입니다.
참고 - 이것은 GameCenter API를 사용할 수 있는지 확인한 것으로 간주합니다.
- (void)checkLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (localPlayer.isAuthenticated)
{
/* Perform additional tasks for the authenticated player here */
}
else
{
/* Perform additional tasks for the non-authenticated player here */
}
}
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] \
compare:v options:NSNumericSearch] == NSOrderedAscending)
- (void)authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
{
// ios 5.x and below
[localPlayer authenticateWithCompletionHandler:^(NSError *error)
{
[self checkLocalPlayer];
}];
}
else
{
// ios 6.0 and above
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (!error && viewcontroller)
{
[[AppDelegate sharedDelegate].viewController
presentViewController:viewcontroller animated:YES completion:nil];
}
else
{
[self checkLocalPlayer];
}
})];
}
}
}
잘 작동합니다! 그래도 사용 중지 된 메소드에 대한 경고 플래그를 제거 할 수 있습니까? – msgambel
배포 목표를 예 : 5.0 또는 대상이 무엇이든간에 - 프로젝트 (프로젝트 탐색기의 맨 위 줄)를 선택하고 대상> 요약> 배포 대상에서 앱을 선택합니다. –
이것은 내가 생각해 낸 것입니다. 작동하는 것 같습니다. 내가 무엇이든 놓쳤다 고 생각하면 편집 해주십시오.
-(void)authenticatePlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (!error) {
[self presentViewController:viewcontroller animated:YES completion:^{
if (localPlayer.isAuthenticated)
{
// your code if authenticated
}
else {
// your code if not authenticated
}
}];
}
else {
// error handling code here
}
})];
}
iOS 6 이상에서는이 코드를 사용하고 있습니다. 컴파일러 오류가 없으며 제대로 작동하는 것 같습니다.
#pragma
#pragma mark - Player Authentication
-(void)autheticatePlayer
{
__weak typeof(self) weakSelf = self; // removes retain cycle error
_localPlayer = [GKLocalPlayer localPlayer]; // localPlayer is the public GKLocalPlayer
__weak GKLocalPlayer *weakPlayer = _localPlayer; // removes retain cycle error
weakPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if (viewController != nil)
{
[weakSelf showAuthenticationDialogWhenReasonable:viewController];
}
else if (weakPlayer.isAuthenticated)
{
[weakSelf authenticatedPlayer:weakPlayer];
}
else
{
[weakSelf disableGameCenter];
}
};
}
-(void)showAuthenticationDialogWhenReasonable:(UIViewController *)controller
{
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:controller animated:YES completion:nil];
}
-(void)authenticatedPlayer:(GKLocalPlayer *)player
{
player = _localPlayer;
}
-(void)disableGameCenter
{
}
- 1. 어떻게하면 svn_cat을 사용할 수 있습니까?
- 2. 어떻게하면 안드로이드에서 vitamio 플레이어를 사용할 수 있습니까?
- 3. 어떻게하면 getJSON에서 가져온 데이터를 사용할 수 있습니까?
- 4. 어떻게하면 방화벽 뒤에있는 git을 사용할 수 있습니까?
- 5. 어떻게하면 appendTo와 insertBefore를 올바르게 사용할 수 있습니까?
- 6. 어떻게하면 Git과 Git Extension을 사용할 수 있습니까?
- 7. 어떻게하면 Sciss를 Mysql과 함께 사용할 수 있습니까?
- 8. 어떻게하면 vba.net 대신 vba를 사용할 수 있습니까?
- 9. 어떻게하면 Google지도 API를 iphone에 사용할 수 있습니까?
- 10. 어떻게하면 모든 것을 사용할 수 있습니까? C++
- 11. 어떻게하면 내 asp.net 프로젝트에서 동적 LINQ를 사용할 수 있습니까?
- 12. 어떻게하면 @와 .com을 내 앱에서 ios 키보드로 사용할 수 있습니까?
- 13. 어떻게하면 Play 프레임 워크에서 복합 키를 사용할 수 있습니까?
- 14. 어떻게하면 TUDPSocket을 Borland C++ Builder에서 사용할 수 있습니까?
- 15. 어떻게하면 객체의 여러 메소드에서 functools.partial을 사용할 수 있습니까?
- 16. 어떻게하면 MVC3에서 하나 이상의 레이아웃을 추가하고 사용할 수 있습니까?
- 17. 어떻게하면 git main과 sub modules에 하나의 커밋을 사용할 수 있습니까?
- 18. 어떻게하면 std :: for_each와 boost :: bimap을 사용할 수 있습니까?
- 19. 어떻게하면 키보드만을 사용하여 asp.net에서 효율적으로 Gridview를 사용할 수 있습니까?
- 20. 어떻게하면 PK를 늘릴 수 있습니까?
- 21. 어떻게하면 PDOException을 발생시킬 수 있습니까?
- 22. 어떻게하면 단추로 만들 수 있습니까?
- 23. 어떻게하면 JBOSS를 줄일 수 있습니까?
- 24. 어떻게하면 git 사용자를 병합 할 수 있습니까?
- 25. 어떻게하면 CABasicAnimation이 애니메이션으로 콜백 할 수 있습니까?
- 26. 어떻게하면 Cocoa로 폴더를 모니터링 할 수 있습니까?
- 27. 어떻게하면 반대편에있는 상태 변수를 얻을 수 있습니까?
- 28. 어떻게하면 목록 상자를 * 크기로 만들 수 있습니까?
- 29. 어떻게하면 더 정확한 위치를 얻을 수 있습니까?
- 30. 어떻게하면 html로 된 URL을 일치시킬 수 있습니까?
API diff를 읽습니다. –