ios开发手册中文版

浏览23820
更新时间2022-04-11

IOS GameKit


简介

GameKit是iOS SDK中一个常用的框架。其核心功能有3个:

  • 交互游戏平台Game Center,
  • P2P设备通讯功能
  • In-Game Voice。

实例步骤

1.在链接 iTunes 时请确保拥有一个唯一的 App ID( unique App ID),App ID在我们应用程序更新 bundle ID时及在Xcode代码签名与相应的配置文件需要使用到。

2.创建新的应用程序和更新应用程序信息。在添加新的应用程序文档可以了解更多有关信息。

3.打开你申请的application,点击Manage Game Center选项。进入后点击Enable Game Center使你的Game Center生效。接下来设置自己的Leaderboard和Achievements。

4.下一步涉及处理代码,并为我们的应用程序创建用户界面。

5.创建一个single view application,并输入 bundle identifier 。

6.更新 ViewController.xib,如下所示

gamekitInterface

7.选择项目文件,然后选择目标,然后添加GameKit.framework

8.为已添加的按钮创建IBActions

9.更新ViewController.h文件,如下所示

#import <UIKit/UIKit.h>#import <GameKit/GameKit.h>@interface ViewController : UIViewController<GKLeaderboardViewControllerDelegate>-(IBAction)updateScore:(id)sender;-(IBAction)showLeaderBoard:(id)sender;@end

10.更新ViewController.m ,如下所示

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];    if([GKLocalPlayer localPlayer].authenticated == NO)    {      [[GKLocalPlayer localPlayer] 
      authenticateWithCompletionHandler:^(NSError *error)      {         NSLog(@"Error%@",error);      }];    }    }- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}- (void) updateScore: (int64_t) score 
forLeaderboardID: (NSString*) category{    GKScore *scoreObj = [[GKScore alloc]
    initWithCategory:category];
    scoreObj.value = score;
    scoreObj.context = 0;    [scoreObj reportScoreWithCompletionHandler:^(NSError *error) {        // Completion code can be added here        UIAlertView *alert = [[UIAlertView alloc]
        initWithTitle:nil message:@"Score Updated Succesfully" 
        delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];        [alert show];    }];}-(IBAction)updateScore:(id)sender{    [self updateScore:200 forLeaderboardID:@"tutorialsPoint"];}-(IBAction)showLeaderBoard:(id)sender{    GKLeaderboardViewController *leaderboardViewController =    [[GKLeaderboardViewController alloc] init];
    leaderboardViewController.leaderboardDelegate = self;    [self presentModalViewController:
    leaderboardViewController animated:YES];}#pragma mark - Gamekit delegates- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController{    [self dismissModalViewControllerAnimated:YES];}@end

输出

运行该应用程序,输出结果如下

gamekit_Output1

当我们单击显示排行榜时,屏幕显示如下:

gamekit_Output2

当我们点击更新分数,比分将被更新到我们排行榜上,我们会得到一个信息,如下图所示

gamekit_Output3

相关视频

更多

免费

微信小程序--企业微网站
初级微信小程序--企业微网站

5.4万次学习

收藏

免费

微信小程序开发基础教程
初级微信小程序开发基础教程

6.8万次学习

收藏

免费

微信小程序基础API篇
高级微信小程序基础API篇

3.5万次学习

收藏

免费

微信小程序--微商城
高级微信小程序--微商城

3.9万次学习

收藏

精品课程

更多
前端入门_HTML5
前端入门_HTML5

共29课时

65万人学习

CSS视频教程-玉女心经版
CSS视频教程-玉女心经版

共25课时

41.3万人学习

JavaScript极速入门_玉女心经系列
JavaScript极速入门_玉女心经系列

共43课时

76.8万人学习

独孤九贱(1)_HTML5视频教程
独孤九贱(1)_HTML5视频教程

共25课时

64.2万人学习

独孤九贱(2)_CSS视频教程
独孤九贱(2)_CSS视频教程

共22课时

24.4万人学习

独孤九贱(3)_JavaScript视频教程
独孤九贱(3)_JavaScript视频教程

共28课时

36.3万人学习

独孤九贱(4)_PHP视频教程
独孤九贱(4)_PHP视频教程

共89课时

133.4万人学习

热门下载

更多
phpStudy 2018最新版
phpStudy 2018最新版

集成PHP7,16种组合,超全大合集

下载

VC9 32位
VC9 32位

VC9 32位 phpstudy集成安装环境运行库

下载

VC11 32位
VC11 32位

VC11 32位 phpstudy集成安装环境运行库​

下载

php程序员工具箱完整版
php程序员工具箱完整版

程序员工具箱 v1.0 php集成环境

下载

VC14 32位
VC14 32位

VC14 32位 phpstudy安装环境运行库

下载

SublimeText3汉化版
SublimeText3汉化版

中文版,非常好用

下载

Notepad++ Windows版
Notepad++ Windows版

Notepad++ 8.9.7 Windows版官方安装包,适合 Windows 用户进行代码编辑、文本处理、语法高亮和插件扩展配置。

下载