Ios Gamekit
* * *
## Introduction
GameKit is a commonly used framework in the iOS SDK. Its core features include three main components:
* The interactive gaming platform Game Center,
* Peer-to-peer (P2P) device communication functionality,
* In-Game Voice.
## Example Steps
1. When linking with iTunes, ensure you have a unique App ID. This App ID is required when updating your application's bundle ID and configuring code signing along with the appropriate provisioning profile in Xcode.
2. Create a new application and update its information. Refer to the documentation on adding new applications for more details.
3. Open your registered application and click the "Manage Game Center" option. After entering, click "Enable Game Center" to activate Game Center for your app. Then set up your own Leaderboard and Achievements.
4. The next step involves handling code and creating the user interface for our application.
5. Create a single view application and enter the bundle identifier.
6. Update ViewController.xib as shown below:

7. Select the project file, then select the target, and add GameKit.framework.
8. Create IBActions for the added buttons.
9. Update the ViewController.h file as follows:
#import #import @interface ViewController : UIViewController-(IBAction)updateScore:(id)sender;-(IBAction)showLeaderBoard:(id)sender;@end
10. Update ViewController.m as follows:
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { ; if(.authenticated == NO) { [ authenticateWithCompletionHandler:^(NSError *error) { NSLog(@"Error%@",error); }]; } }- (void)didReceiveMemoryWarning { ; // Dispose of any resources that can be recreated.}- (void) updateScore: (int64_t) score forLeaderboardID: (NSString*) category { GKScore *scoreObj = [ initWithCategory:category]; scoreObj.value = score; scoreObj.context = 0; [scoreObj reportScoreWithCompletionHandler:^(NSError *error) { // Completion code can be added here UIAlertView *alert = [ initWithTitle:nil message:@"Score Updated Succesfully" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil]; ; }];}-(IBAction)updateScore:(id)sender{ [self updateScore:200 forLeaderboardID:@""];}-(IBAction)showLeaderBoard:(id)sender{ GKLeaderboardViewController *leaderboardViewController = [ init]; leaderboardViewController.leaderboardDelegate = self; [self presentModalViewController: leaderboardViewController animated:YES];}#pragma mark - Gamekit delegates - (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController{ [self dismissModalViewControllerAnimated:YES];}@end
### Output
When running the application, the output appears as follows:

When we click "Show Leaderboard," the screen displays as shown below:

When we click "Update Score," the score will be updated on our leaderboard, and we'll receive a message as shown in the image below:

YouTip