When Game Center was released, I thought, “Ha, wouldn’t it be fun to have Game Center in one of my apps!”. Well, I added support in BART Fares and the free update was released last week.
To do so, I added the GameKit
Framework into the project and appended #import
into the view controller’s header. When the user checked in at a particular place, code to earn an achievement were run. The code I modified and used from Apple’s documentation is:
NSString *identifier = @"fareidentifier";<br />
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease];<br />
if (achievement) {<br />
achievement.percentComplete = 100;<br />
[achievement reportAchievementWithCompletionHandler:^(NSError *error)<br />
{<br />
if(error != nil) {<br />
NSLog(@"error with %@ achievement",identifier);<br />
}}];<br />
}
The “identifier” string would be replaced with the appropriate achievement’s identifier. The location based achievements in the app did not incorporate progress, so I simply set the percent complete to 100. If there is an error, the program would spit out the achievement identifier. You could have it display the error, too.
Note: If progress is needed, you may want to just store the current progress and just add and subtract to its value whenever the correct/incorrect action is triggered.
Now the creative part starts. You can login to iTunes Connect to create and save achievements. I took most pictures using my [iphone] camera. Even though the image needs to be 512x512px, they’ll be displayed in 50x50px circles on the devices. If you’re still reading this, you should try out BART Fares on your idevice; the app is free. Game Center is a great way to get attention and will make the user want to use the app more.