Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm from BivisSoft. We've developed Bubblin.</p> <p>We have a Singleton that controls GameCenter.</p> <p>Here is our code... It's based on tutorial by Jacob Gundersen - <a href="http://www.raywenderlich.com/5480/beginning-turn-based-gaming-with-ios-5-part-1" rel="nofollow">http://www.raywenderlich.com/5480/beginning-turn-based-gaming-with-ios-5-part-1</a>.</p> <p>You can try it!</p> <pre><code> #pragma mark Singleton static BSGameCenterManager *sharedHelper = nil; + (BSGameCenterManager *) sharedInstance { if (!sharedHelper) { sharedHelper = [[BSGameCenterManager alloc] init]; } return sharedHelper; } #pragma mark Initializers - (id)init { if ((self = [super init])) { gameCenterAvailable = [self isGameCenterAvailable]; if (gameCenterAvailable) { self.localPlayerId = @""; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(authenticationChanged) name:GKPlayerAuthenticationDidChangeNotificationName object:nil]; } } return self; } // Check if GameCenter is Avaiable - (BOOL)isGameCenterAvailable { // check for presence of GKLocalPlayer API Class gcClass = (NSClassFromString(@"GKLocalPlayer")); // check if the device is running iOS 4.1 or later NSString *reqSysVer = @"4.1"; NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending); return (gcClass &amp;&amp; osVersionSupported); } #pragma mark Authentication - (void)authenticationChanged { if ([GKLocalPlayer localPlayer].isAuthenticated &amp;&amp; !self.userAuthenticated) { NSLog(@"GameCenter authentication changed: player authenticated."); self.userAuthenticated = TRUE; self.localPlayerId = [[GKLocalPlayer localPlayer] playerID]; [[NSNotificationCenter defaultCenter] postNotificationName: @"gameCenterPlayerAuthenticated" object: nil userInfo: nil]; [self checkNotSentScores]; } else if (![GKLocalPlayer localPlayer].isAuthenticated &amp;&amp; self.userAuthenticated) { NSLog(@"GameCenter authentication changed: player not authenticated"); self.userAuthenticated = FALSE; self.localPlayerId = @""; } } - (void)authenticateLocalUser { if (!gameCenterAvailable) return; NSLog(@"GameCenter authenticating local user..."); if ([GKLocalPlayer localPlayer].authenticated == NO) { [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil]; } else { NSLog(@"GameCenter already authenticated!"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload