中国法律网
法律通行证: 用户名: 密码:  注册
律师加盟热线:400-8919-913   律信通 律信通  
律师
公众 咨询 贴吧
律信通 案件委托
频道 房产 婚姻 交通事故 保险 建设工程 劳动
留学
公司 合同 刑事辩护 医疗 知识产权 工商
新闻 宽频 文书 常识 案例
法规 专题 杂志 百科 论文
查找全国各地律师: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 点击各城市名拼音首字母查找律师 公众找律师,信赖律信通!律师做宣传,首选律信通!
当前位置: 主页 > 法律专题2 > 申请的格式 >

【iOS开发必备指南合集】申请企业级IDP、真机调试、游戏接入Game(3)

时间:2013-08-15 00:08来源:互联网 作者:admin 点击:
6.对Achievement进行操作 这一部分内容比较多,而且有的地方有点重复的感觉. 6.1汇报一个成就的进度 对于一个玩家可见的成就,你需要尽可能的报告给玩家解锁的进度;对于一个一部完成的成就,则不需要,当玩家的进度达到

6.对Achievement进行操作
这一部分内容比较多,而且有的地方有点重复的感觉.
6.1汇报一个成就的进度
对于一个玩家可见的成就,你需要尽可能的报告给玩家解锁的进度;对于一个一部完成的成就,则不需要,当玩家的进度达到100%的时候,会自动解锁该成就.

- (void) reportAchievementIdentifier: (NSString*) identifier percentComplete: (float) percent { GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease]; if (achievement) { achievement.percentComplete = percent; [achievement reportAchievementWithCompletionHandler:^(NSError *error) { if (error != nil) { //The proper way for your application to handle network errors is retain //the achievement object (possibly adding it to an array). Then, periodically //attempt to report the progress until it is successfully reported. //The GKAchievement class supports the NSCoding protocol to allow your //application to archive an achie NSLog(@"报告成就进度失败 ,错误信息为: \n %@",error); }else { //对用户提示,已经完成XX%进度 NSLog(@"报告成就进度---->成功!"); NSLog(@" completed:%d",achievement.completed); NSLog(@" hidden:%d",achievement.hidden); NSLog(@" lastReportedDate:%@",achievement.lastReportedDate); NSLog(@" percentComplete:%f",achievement.percentComplete); NSLog(@" identifier:%@",achievement.identifier); } }]; } }

其中该函数的参数中identifier是你成就的ID, percent是该成就完成的百分比

6.2读取一个成就
方法一:得到所有的成就

- (void) loadAchievements { NSMutableDictionary *achievementDictionary = [[NSMutableDictionary alloc] init]; [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements,NSError *error) { if (error == nil) { NSArray *tempArray = [NSArray arrayWithArray:achievements]; for (GKAchievement *tempAchievement in tempArray) { [achievementDictionary setObject:tempAchievement forKey:tempAchievement.identifier]; NSLog(@" completed:%d",tempAchievement.completed); NSLog(@" hidden:%d",tempAchievement.hidden); NSLog(@" lastReportedDate:%@",tempAchievement.lastReportedDate); NSLog(@" percentComplete:%f",tempAchievement.percentComplete); NSLog(@" identifier:%@",tempAchievement.identifier); } } }]; }

函数中NSArray返回的是你的所有成就ID.

方法二:根据ID获取成就

- (GKAchievement*) getAchievementForIdentifier: (NSString*) identifier { NSMutableDictionary *achievementDictionary = [[NSMutableDictionary alloc] init]; GKAchievement *achievement = [achievementDictionary objectForKey:identifier]; if (achievement == nil) { achievement = [[[GKAchievement alloc] initWithIdentifier:identifier] autorelease]; [achievementDictionary setObject:achievement forKey:achievement.identifier]; } return [[achievement retain] autorelease]; }

6.3获取成就描述和图片
在自定义界面中,玩家需要一个成就描述,以及该成就的图片,Game Center提供了该功能.当然,你也可以自己在程序中完成,毕竟玩家不可能时刻处于在线状态.

- (NSArray*)retrieveAchievmentMetadata { //读取成就的描述 [GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler: ^(NSArray *descriptions, NSError *error) { if (error != nil) { // process the errors NSLog(@"读取成就说明出错"); } if (descriptions != nil) { // use the achievement descriptions. for (GKAchievementDescription *achDescription in descriptions) { NSLog(@"1..identifier..%@",achDescription.identifier); NSLog(@"2..achievedDescription..%@",achDescription.achievedDescription); NSLog(@"3..title..%@",achDescription.title); NSLog(@"4..unachievedDescription..%@",achDescription.unachievedDescription); NSLog(@"5............%@",achDescription.image); //获取成就图片,如果成就未解锁,返回一个大文号 /* [achDescription loadImageWithCompletionHandler:^(UIImage *image, NSError *error) { if (error == nil) { // use the loaded image. The image property is also populated with the same image. NSLog(@"成功取得成就的图片"); UIImage *aImage = image; UIImageView *aView = [[UIImageView alloc] initWithImage:aImage]; aView.frame = CGRectMake(50, 50, 200, 200); aView.backgroundColor = [UIColor clearColor]; [[[CCDirector sharedDirector] openGLView] addSubview:aView]; }else { NSLog(@"获得成就图片失败"); } }]; */ } } }]; return nil; }

如果你不主动使用注释中的方法,那么你得到的description中不会有图片,这样可以减少网络的使用,尽量少下载东西.当使用注释中的代码时,如果成就已经解锁,则返回该成就的图标,如果没有解锁,则返回一个大问号,至于未解锁图标是否可以自定义,我找寻的结果好像是不可以.

GameCenter 成就提示更新:

GameCenter中成就提示需要开发者自定义,即使官方Demo的例子程序中也没有给与提示框(横幅样式)通知用户的官方代码,所以这里Himi介绍如何模仿官方的成就提示:

1. iOS5以及更高SDK中,apple已经提供官方的成就提示:方法很简单,代码如下:

- (void)sendAchievement:(GKAchievement *)achievement { achievement.percentComplete = 100.0; //Indicates the achievement is done achievement.showsCompletionBanner = YES; //Indicate that a banner should be shown [achievement reportAchievementWithCompletionHandler: ^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^(void) { if (error == NULL) { NSLog(@"Successfully sent archievement!"); } else { NSLog(@"Achievement failed to send... will try again \ later. Reason: %@", error.localizedDescription); } }); }]; }

将“showsCompletionBanner”属性设置成YES,提交给苹果。新iOS属性“showsCompletionBanner”,其默认设置是NO,但若将其调整成YES,屏幕就呈现包含成就标题和描述的漂亮横幅;

 

2.如果低于5.0的SDK设备中是没有“showsCompletionBanner”属性的,所以需要我们自定义提示样式,当然这里Himi也分享一下如何模仿官方横幅提示样式的方法和代码:

(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
用户名: 验证码: 点击我更换图片
栏目列表
推荐内容
中国法律网 版权所有 邮箱:service@5Law.cn 建议使用:1024x768分辨率,16位以上颜色 | 京ICP备2023040428号-1联系我们 有事点这里    [切换城市▲] 公司法
400-8919-913 工作日:9:00-18:00
周 六:9:00-12:00

法律咨询5分钟内回复
请用微信扫描二维码
关闭

关注网站CEO微信,与CEO对话