{"id":190930,"date":"2022-04-15T04:44:46","date_gmt":"2022-04-14T20:44:46","guid":{"rendered":"https:\/\/www.idc.net\/help\/190930\/"},"modified":"2022-04-15T04:44:46","modified_gmt":"2022-04-14T20:44:46","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91ios%e6%95%99%e7%a8%8b%ef%bc%9aios-gamekit","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/190930\/","title":{"rendered":"\u540e\u6d6a\u4e91IOS\u6559\u7a0b\uff1aiOS GameKit"},"content":{"rendered":"<h2>IOS GameKit<\/h2>\n<hr>\n<h2>\u7b80\u4ecb<\/h2>\n<p>GameKit\u662fiOS SDK\u4e2d\u4e00\u4e2a\u5e38\u7528\u7684\u6846\u67b6\u3002\u5176\u6838\u5fc3\u529f\u80fd\u67093\u4e2a\uff1a<\/p>\n<ul>\n<li>\u4ea4\u4e92\u6e38\u620f\u5e73\u53f0Game Center\uff0c<\/li>\n<li>P2P\u8bbe\u5907\u901a\u8baf\u529f\u80fd<\/li>\n<li>In-Game Voice\u3002<\/li>\n<\/ul>\n<h2>\u5b9e\u4f8b\u6b65\u9aa4<\/h2>\n<p>1.\u5728\u94fe\u63a5 iTunes \u65f6\u8bf7\u786e\u4fdd\u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7684 App ID\uff08 unique App ID\uff09\uff0cApp ID\u5728\u6211\u4eec\u5e94\u7528\u7a0b\u5e8f\u66f4\u65b0 bundle ID\u65f6\u53ca\u5728Xcode\u4ee3\u7801\u7b7e\u540d\u4e0e\u76f8\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\u9700\u8981\u4f7f\u7528\u5230\u3002<\/p>\n<p>2.\u521b\u5efa\u65b0\u7684\u5e94\u7528\u7a0b\u5e8f\u548c\u66f4\u65b0\u5e94\u7528\u7a0b\u5e8f\u4fe1\u606f\u3002\u5728\u6dfb\u52a0\u65b0\u7684\u5e94\u7528\u7a0b\u5e8f\u6587\u6863\u53ef\u4ee5\u4e86\u89e3\u66f4\u591a\u6709\u5173\u4fe1\u606f\u3002<\/p>\n<p>3.\u6253\u5f00\u4f60\u7533\u8bf7\u7684application,\u70b9\u51fbManage Game Center\u9009\u9879\u3002\u8fdb\u5165\u540e\u70b9\u51fbEnable Game Center\u4f7f\u4f60\u7684Game Center\u751f\u6548\u3002\u63a5\u4e0b\u6765\u8bbe\u7f6e\u81ea\u5df1\u7684Leaderboard\u548cAchievements\u3002<\/p>\n<p>4.\u4e0b\u4e00\u6b65\u6d89\u53ca\u5904\u7406\u4ee3\u7801\uff0c\u5e76\u4e3a\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u521b\u5efa\u7528\u6237\u754c\u9762\u3002<\/p>\n<p>5.\u521b\u5efa\u4e00\u4e2asingle view application\uff0c\u5e76\u8f93\u5165 bundle identifier \u3002<\/p>\n<p>6.\u66f4\u65b0 ViewController.xib\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211704491822.jpg\" class=\"aligncenter\"><\/p>\n<p>7.\u9009\u62e9\u9879\u76ee\u6587\u4ef6\uff0c\u7136\u540e\u9009\u62e9\u76ee\u6807\uff0c\u7136\u540e\u6dfb\u52a0GameKit.framework<\/p>\n<p>8.\u4e3a\u5df2\u6dfb\u52a0\u7684\u6309\u94ae\u521b\u5efaIBActions<\/p>\n<p>9.\u66f4\u65b0ViewController.h\u6587\u4ef6\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>#import &lt;UIKit\/UIKit.h&gt;\n#import &lt;GameKit\/GameKit.h&gt;\n\n@interface ViewController : UIViewController\n&lt;GKLeaderboardViewControllerDelegate&gt;\n\n-(IBAction)updateScore:(id)sender;\n-(IBAction)showLeaderBoard:(id)sender;\n\n@end\n<\/pre>\n<p>10.\u66f4\u65b0ViewController.m \uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre>#import \"ViewController.h\"\n\n@interface ViewController ()\n\n@end\n\n@implementation ViewController\n\n- (void)viewDidLoad\n{\n    [super viewDidLoad];\n    if([GKLocalPlayer localPlayer].authenticated == NO)\n    {\n      [[GKLocalPlayer localPlayer] \n      authenticateWithCompletionHandler:^(NSError *error)\n      {\n         NSLog(@\"Error%@\",error);\n      }];\n    }    \n}\n\n- (void)didReceiveMemoryWarning\n{\n    [super didReceiveMemoryWarning];\n    \/\/ Dispose of any resources that can be recreated.\n}\n- (void) updateScore: (int64_t) score \nforLeaderboardID: (NSString*) category\n{\n    GKScore *scoreObj = [[GKScore alloc]\n    initWithCategory:category];\n    scoreObj.value = score;\n    scoreObj.context = 0;\n    [scoreObj reportScoreWithCompletionHandler:^(NSError *error) {\n        \/\/ Completion code can be added here\n        UIAlertView *alert = [[UIAlertView alloc]\n        initWithTitle:nil message:@\"Score Updated Succesfully\" \n        delegate:self cancelButtonTitle:@\"Ok\" otherButtonTitles: nil];\n        [alert show];\n\n    }];\n}\n-(IBAction)updateScore:(id)sender{\n    [self updateScore:200 forLeaderboardID:@\"tutorialsPoint\"];\n}\n-(IBAction)showLeaderBoard:(id)sender{\n    GKLeaderboardViewController *leaderboardViewController =\n    [[GKLeaderboardViewController alloc] init];\n    leaderboardViewController.leaderboardDelegate = self;\n    [self presentModalViewController:\n    leaderboardViewController animated:YES];\n\n}\n#pragma mark - Gamekit delegates\n- (void)leaderboardViewControllerDidFinish:\n(GKLeaderboardViewController *)viewController{\n    [self dismissModalViewControllerAnimated:YES];\n}\n\n@end\n<\/pre>\n<h3>\u8f93\u51fa<\/h3>\n<p>\u8fd0\u884c\u8be5\u5e94\u7528\u7a0b\u5e8f\uff0c\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211705068439.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5f53\u6211\u4eec\u5355\u51fb\u663e\u793a\u6392\u884c\u699c\u65f6\uff0c\u5c4f\u5e55\u663e\u793a\u5982\u4e0b:<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211705136839.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5f53\u6211\u4eec\u70b9\u51fb\u66f4\u65b0\u5206\u6570\uff0c\u6bd4\u5206\u5c06\u88ab\u66f4\u65b0\u5230\u6211\u4eec\u6392\u884c\u699c\u4e0a\uff0c\u6211\u4eec\u4f1a\u5f97\u5230\u4e00\u4e2a\u4fe1\u606f\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/atts.IDC.NET.cn\/attachments\/day_171121\/201711211705188163.jpg\" class=\"aligncenter\"><\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>IOS GameKit \u7b80\u4ecb GameKit\u662fiOS SDK\u4e2d\u4e00\u4e2a\u5e38\u7528\u7684\u6846\u67b6\u3002\u5176\u6838\u5fc3\u529f\u80fd\u67093\u4e2a\uff1a \u4ea4\u4e92\u6e38\u620f\u5e73\u53f0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":190931,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189686],"tags":[],"class_list":["post-190930","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=190930"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/190930\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/190931"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=190930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=190930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=190930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}