【iOS开发必备指南合集一】申请IDP/真机调试/GameCenter 指南/OpenFeint指南

简介:

 这里Himi给出对于开发iOS的朋友们整理一个指南集合,其中主要包括申请IDP需要注意的地方、有了开发者证书如何真机调试、在自己的游戏应用中如何接入GameCenter以及如何在游戏接入OpenFeint;

 

        -----------申请企业级IDP,或者个人IDP

       通过Himi的申请经验,直接打苹果在中国的客服,按照步骤一步一步详细的让客服进行指导,可能很多童鞋说我这句跟没说一样,呵呵,如果真的你是第一次申请IDP那么如果你不打客服,N多细节都会造成你1~15天耐心等待,Himi申请过程中由于一个名称和一个勾选错误整整耽误一个月的时间;最后仍是不停的跟客服交涉终于Ok顺利申请到;

     这里Himi给出苹果在中国的客服电话:4006701855 (建议拨打客服之前大致的先百度google下申请IDP的流程,网上一大堆,这里Himi不赘述了)

 

      ---------------申请到IDP后如何真机调试

     1.制作证书的过程Himi这里不多赘述,百度、google下N多文章呢;制作证书连接(前提是申请IDP成功):http://developer.apple.com/membercenter/index.action

     2.正确制作证书后,有个这样的文件:

双击此文件,弹出Organizer-Devices界面,连接你的真机iphone、ipad或者touch,然后左侧可以看到如下图:

右侧的绿色小灯表示可以正常使用,这个小灯如果是黄色,那就说明你的证书有问题,可能是此手机的UDID没有在证书内等原因;

     3.确保真机正常后,点击你的项目,右侧点击PROJECT点击Build Settings页面,然后Code Signing下设置Code Signing Identity为你的证书,如下图:

 

4.点击你的项目,右侧点击TARGETS,点击Info页面下的设置Bundle identifier,这个Bundle identifier在你制作证书的过程中就会了解到,如下图

OK,可以编译运行你的项目到真机中了;

 

 

     ---------------游戏接入GameCenter 指南


1.    iTunes Connect 设置

 

    首先,申请一个应用程序,不必提交.目地是为了得到Bundle ID.
    然后设置一下工程中Info.plist的Bundle identifier使之与iTunes Connect中的Bundle ID相同,否则当你尝试登录GameCenter的时候,会提示一个不支持GameCenter的错误.
    申请完毕,打开你刚申请的application,点击Manage Game Center选项.

进入后点击Enable Game Center使你的Game Center生效.
    接下来就可以设置自己的Leaderboard和Achievements.

2.    Leaderboard设置
    Leaderboard纵观图如下所示.

1.sort Order: Leaderboard中的内容是以升序还是降序排列.
    2.Score Format Type:分数的类型.
    3.*Categories:Leaderboard的一个分数榜,这个可以创建多个,比如游戏可以分为Easy,Normal,Hard三个难度,每个难度一个榜.

*设置完成后保存,完成了一个 Leaderboard的设置.我们可以根据需要添加多个 leaderboard.
    4.**Score Format Location: leaderboard支持的语言.

 

 **可以支持多种语言,每支持一种语言,需要完成一个上述操作.
这个时候右下角会出现save change按钮,点击完成leaderboard的设置.
你可以根据需要随时更改你的leaderboard,操作与上述内容类似.

3.    Achievements设置
    Achievements界面内容比较少,点击左上角的Add New Achievement,打开如下图所示的Achievements创建界面.

Hidden:表示该成就为解锁前玩家是否可见.
    Achievement ID:程序通过这个属性来识别成就.
    *Achievement Localization:该成就支持的语言.
    *Achievement Localization设置如下图所示. 

 *其中,成就的Image必须是512X512,72DPI的.
一切设置完成后,点击save change按钮即完成一个成就的设置.

4.总体功能
在使用各个功能前,你需要了解一下块函数。传送门: https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html

4.1 对Game Center支持判断


  
  
  1. - (BOOL) isGameCenterAvailable   
  2.   {   
  3.       Class gcClass = (NSClassFromString(@"GKLocalPlayer"));   
  4.        NSString *reqSysVer = @"4.1";   
  5.        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];   
  6.        BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);   
  7.          
  8.       return (gcClass && osVersionSupported);   
  9.    }   

4.2用户登录

 


  
  
  1. - (void) authenticateLocalPlayer   
  2.    {   
  3.        [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){   
  4.           if (error == nil) {   
  5.               //成功处理   
  6.               NSLog(@"成功");   
  7.               NSLog(@"1--alias--.%@",[GKLocalPlayer localPlayer].alias);   
  8.                NSLog(@"2--authenticated--.%d",[GKLocalPlayer localPlayer].authenticated);   
  9.               NSLog(@"3--isFriend--.%d",[GKLocalPlayer localPlayer].isFriend);   
  10.               NSLog(@"4--playerID--.%@",[GKLocalPlayer localPlayer].playerID);   
  11.              NSLog(@"5--underage--.%d",[GKLocalPlayer localPlayer].underage);   
  12.          }else {   
  13.               //错误处理   
  14.              NSLog(@"失败  %@",error);   
  15.           }   
  16.      }];   
  17.   }   

对于开发者来说,Game Center必须经过测试才能上线,没有上线的程序在测试环境中登录时会出现sandbox提示.如图. 

4.3用户变更检测
由于4.0以后系统支持多任务,玩家的机器有可能被不同的玩家接触,导致Game Center上的用户发生变化,当发生变化的时候,程序必须在游戏中通知玩家.

 


  
  
  1. - (void) registerForAuthenticationNotification   
  2.    {   
  3.        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];   
  4.        [nc addObserver:self   
  5.               selector:@selector(authenticationChanged)   
  6.                    name:GKPlayerAuthenticationDidChangeNotificationName   
  7.                 object:nil];   
  8.    }   
  9.       
  10.   - (void) authenticationChanged   
  11.   {   
  12.        if ([GKLocalPlayer localPlayer].isAuthenticated)   
  13.        {   
  14.            ;// Insert code here to handle a successful authentication.   
  15.        }   
  16.       else   
  17.       {   
  18.           ;// Insert code here to clean up any outstanding Game Center-related classes.   
  19.      }   
  20.   }   

5.对Leaderboard进行操作
5.1上传一个分数

 


  
  
  1. - (void) reportScore: (int64_t) score forCategory: (NSString*) category   
  2.   {   
  3.      GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];   
  4.       scoreReporter.value = score;   
  5.          
  6.        [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {   
  7.           if (error != nil)   
  8.           {   
  9.              // handle the reporting error   
  10.               NSLog(@"上传分数出错.");   
  11.              //If your application receives a network error, you should not discard the score.   
  12.              //Instead, store the score object and attempt to report the player’s process at   
  13.               //a later time.   
  14.           }else {   
  15.              NSLog(@"上传分数成功");   
  16.          }   
  17.     
  18.      }];   
  19.   }   

当上传分数出错的时候,要将上传的分数存储起来,比如将SKScore存入一个NSArray中.等可以上传的时候再次尝试.

5.2下载一个分数

 


  
  
  1. //GKScore objects provide the data your application needs to create a custom view.   
  2.  //Your application can use the score object’s playerID to load the player’s alias.   
  3.   //The value property holds the actual value you reported to Game Center. the formattedValue   
  4.   //property provides a string with the score value formatted according to the parameters   
  5.   //you provided in iTunes Connect.   
  6.   - (void) retrieveTopTenScores   
  7.   {   
  8.      GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];   
  9.     if (leaderboardRequest != nil)   
  10.      {   
  11.         leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;   
  12.         leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;   
  13.         leaderboardRequest.range = NSMakeRange(1,10);   
  14.          leaderboardRequest.category = @"TS_LB";   
  15.          [leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {   
  16.              if (error != nil){   
  17.                  // handle the error.   
  18.                  NSLog(@"下载失败");   
  19.              }   
  20.             if (scores != nil){   
  21.                 // process the score information.   
  22.                 NSLog(@"下载成功....");   
  23.                NSArray *tempScore = [NSArray arrayWithArray:leaderboardRequest.scores];   
  24.                  for (GKScore *obj in tempScore) {   
  25.                    NSLog(@"    playerID            : %@",obj.playerID);   
  26.                     NSLog(@"    category            : %@",obj.category);   
  27.                     NSLog(@"    date                : %@",obj.date);   
  28.                     NSLog(@"    formattedValue    : %@",obj.formattedValue);   
  29.                      NSLog(@"    value                : %d",obj.value);   
  30.                     NSLog(@"    rank                : %d",obj.rank);   
  31.                    NSLog(@"**************************************");   
  32.                  }   
  33.              }   
  34.         }];   
  35.     }   
  36. }   

说明:
1)    playerScope:表示检索玩家分数范围.
2)    timeScope:表示某一段时间内的分数
3)    range:表示分数排名的范围
4)    category:表示你的Leaderboard的ID.

5.3玩家信息交互
Game Center最重要的一个功能就是玩家交互.所以,必须检索已经登录玩家的好友信息.根据自己的需要做出设置,比如,可以与好友比较分数,或者好友排行榜等.
//检索已登录用户好友列表

 


  
  
  1. - (void) retrieveFriends   
  2.  {   
  3.      GKLocalPlayer *lp = [GKLocalPlayer localPlayer];   
  4.      if (lp.authenticated)   
  5.      {   
  6.          [lp loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error) {   
  7.              if (error == nil)   
  8.             {   
  9.                  [self loadPlayerData:friends];   
  10.             }   
  11.             else   
  12.             {   
  13.                 ;// report an error to the user.   
  14.             }   
  15.         }];   
  16.             
  17.     }   
  18. }   

上面的friends得到的只是一个身份列表,里面存储的是NSString,想要转换成好友ID,必须调用- (void) loadPlayerData: (NSArray *) identifiers方法,该方法得到的array里面存储的才是GKPlayer对象.如下

 


  
  
  1. /*  
  2.    Whether you received player identifiers by loading the identifiers for the local player’s  
  3.   friends, or from another Game Center class, you must retrieve the details about that player  
  4.   from Game Center.  
  5.    */   
  6.   - (void) loadPlayerData: (NSArray *) identifiers   
  7.    {   
  8.      [GKPlayer loadPlayersForIdentifiers:identifiers withCompletionHandler:^(NSArray *players, NSError *error) {   
  9.          if (error != nil)   
  10.          {   
  11.               // Handle the error.   
  12.         }   
  13.          if (players != nil)   
  14.          {   
  15.             NSLog(@"得到好友的alias成功");   
  16.              GKPlayer *friend1 = [players objectAtIndex:0];   
  17.             NSLog(@"friedns---alias---%@",friend1.alias);   
  18.             NSLog(@"friedns---isFriend---%d",friend1.isFriend);   
  19.             NSLog(@"friedns---playerID---%@",friend1.playerID);   
  20.          }   
  21.      }];   
  22.  }   

至此,leaderboard功能介绍完毕

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

 


  
  
  1. - (void) reportAchievementIdentifier: (NSString*) identifier percentComplete: (float) percent   
  2.    {   
  3.         GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease];   
  4.        if (achievement)   
  5.       {   
  6.            achievement.percentComplete = percent;   
  7.             [achievement reportAchievementWithCompletionHandler:^(NSError *error)   
  8.              {   
  9.                  if (error != nil)   
  10.                {   
  11.                   //The proper way for your application to handle network errors is retain   
  12.                    //the achievement object (possibly adding it to an array). Then, periodically   
  13.                   //attempt to report the progress until it is successfully reported.   
  14.                   //The GKAchievement class supports the NSCoding protocol to allow your   
  15.                    //application to archive an achie   
  16.                    NSLog(@"报告成就进度失败 ,错误信息为: \n %@",error);   
  17.              }else {   
  18.                     //对用户提示,已经完成XX%进度   
  19.                    NSLog(@"报告成就进度---->成功!");   
  20.                    NSLog(@"    completed:%d",achievement.completed);   
  21.                   NSLog(@"    hidden:%d",achievement.hidden);   
  22.                    NSLog(@"    lastReportedDate:%@",achievement.lastReportedDate);   
  23.                   NSLog(@"    percentComplete:%f",achievement.percentComplete);   
  24.                    NSLog(@"    identifier:%@",achievement.identifier);   
  25.               }   
  26.             }];   
  27.       }   
  28.   }   

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

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

 


  
  
  1. - (void) loadAchievements   
  2.     {   
  3.       NSMutableDictionary *achievementDictionary = [[NSMutableDictionary alloc] init];   
  4.         [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements,NSError *error)   
  5.         {   
  6.             if (error == nil) {   
  7.                NSArray *tempArray = [NSArray arrayWithArray:achievements];   
  8.                 for (GKAchievement *tempAchievement in tempArray) {   
  9.                     [achievementDictionary setObject:tempAchievement forKey:tempAchievement.identifier];   
  10.                    NSLog(@"    completed:%d",tempAchievement.completed);   
  11.                    NSLog(@"    hidden:%d",tempAchievement.hidden);   
  12.                   NSLog(@"    lastReportedDate:%@",tempAchievement.lastReportedDate);   
  13.                    NSLog(@"    percentComplete:%f",tempAchievement.percentComplete);   
  14.                    NSLog(@"    identifier:%@",tempAchievement.identifier);   
  15.                }   
  16.            }   
  17.         }];   
  18.   }   

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

方法二:根据ID获取成就

 


  
  
  1. - (GKAchievement*) getAchievementForIdentifier: (NSString*) identifier   
  2.     {   
  3.        NSMutableDictionary *achievementDictionary = [[NSMutableDictionary alloc] init];   
  4.       GKAchievement *achievement = [achievementDictionary objectForKey:identifier];   
  5.        if (achievement == nil)   
  6.        {   
  7.             achievement = [[[GKAchievement alloc] initWithIdentifier:identifier] autorelease];   
  8.            [achievementDictionary setObject:achievement forKey:achievement.identifier];   
  9.        }   
  10.      return [[achievement retain] autorelease];   
  11.   }   

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

 


  
  
  1. - (NSArray*)retrieveAchievmentMetadata   
  2.   {   
  3.       //读取成就的描述   
  4.       [GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:   
  5.         ^(NSArray *descriptions, NSError *error) {   
  6.           if (error != nil)   
  7.            {   
  8.                 // process the errors   
  9.                 NSLog(@"读取成就说明出错");   
  10.           }   
  11.          if (descriptions != nil)   
  12.            {   
  13.               // use the achievement descriptions.   
  14.               for (GKAchievementDescription *achDescription in descriptions) {   
  15.                    NSLog(@"1..identifier..%@",achDescription.identifier);   
  16.                    NSLog(@"2..achievedDescription..%@",achDescription.achievedDescription);   
  17.                   NSLog(@"3..title..%@",achDescription.title);   
  18.                    NSLog(@"4..unachievedDescription..%@",achDescription.unachievedDescription);   
  19.                  NSLog(@"5............%@",achDescription.image);   
  20.                     
  21.                    //获取成就图片,如果成就未解锁,返回一个大文号   
  22.                   /*  
  23.                   [achDescription loadImageWithCompletionHandler:^(UIImage *image, NSError *error) {  
  24.                       if (error == nil)  
  25.                       {  
  26.                           // use the loaded image. The image property is also populated with the same image.  
  27.                           NSLog(@"成功取得成就的图片");  
  28.                            UIImage *aImage = image;  
  29.                          UIImageView *aView = [[UIImageView alloc] initWithImage:aImage];  
  30.                           aView.frame = CGRectMake(50, 50, 200, 200);  
  31.                           aView.backgroundColor = [UIColor clearColor];  
  32.                           [[[CCDirector sharedDirector] openGLView] addSubview:aView];  
  33.                        }else {  
  34.                          NSLog(@"获得成就图片失败");  
  35.                       }  
  36.                  }];  
  37.                     */   
  38.               }   
  39.           }   
  40.       }];   
  41.     return nil;   
  42.  }   

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

 










本文转自 xiaominghimi 51CTO博客,原文链接:http://blog.51cto.com/xiaominghimi/699764,如需转载请自行联系原作者
目录
相关文章
|
22天前
|
iOS开发 开发者
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
117 67
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
|
2月前
|
iOS开发 开发者 MacOS
深入探索iOS开发中的SwiftUI框架
【10月更文挑战第21天】 本文将带领读者深入了解Apple最新推出的SwiftUI框架,这一革命性的用户界面构建工具为iOS开发者提供了一种声明式、高效且直观的方式来创建复杂的用户界面。通过分析SwiftUI的核心概念、主要特性以及在实际项目中的应用示例,我们将展示如何利用SwiftUI简化UI代码,提高开发效率,并保持应用程序的高性能和响应性。无论你是iOS开发的新手还是有经验的开发者,本文都将为你提供宝贵的见解和实用的指导。
134 66
|
2月前
|
存储 监控 API
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
|
2月前
|
开发框架 Android开发 iOS开发
安卓与iOS开发中的跨平台策略:一次编码,多平台部署
在移动应用开发的广阔天地中,安卓和iOS两大阵营各占一方。随着技术的发展,跨平台开发框架应运而生,它们承诺着“一次编码,到处运行”的便捷。本文将深入探讨跨平台开发的现状、挑战以及未来趋势,同时通过代码示例揭示跨平台工具的实际运用。
161 3
|
2月前
|
Java 调度 Android开发
安卓与iOS开发中的线程管理差异解析
在移动应用开发的广阔天地中,安卓和iOS两大平台各自拥有独特的魅力。如同东西方文化的差异,它们在处理多线程任务时也展现出不同的哲学。本文将带你穿梭于这两个平台之间,比较它们在线程管理上的核心理念、实现方式及性能考量,助你成为跨平台的编程高手。
|
3月前
|
开发框架 前端开发 Android开发
安卓与iOS开发中的跨平台策略
在移动应用开发的战场上,安卓和iOS两大阵营各据一方。随着技术的演进,跨平台开发框架成为开发者的新宠,旨在实现一次编码、多平台部署的梦想。本文将探讨跨平台开发的优势与挑战,并分享实用的开发技巧,帮助开发者在安卓和iOS的世界中游刃有余。
|
3月前
|
存储 前端开发 Swift
探索iOS开发:从新手到专家的旅程
本文将带您领略iOS开发的奇妙之旅,从基础概念的理解到高级技巧的掌握,逐步深入iOS的世界。文章不仅分享技术知识,还鼓励读者在编程之路上保持好奇心和创新精神,实现个人成长与技术突破。
|
3月前
|
安全 IDE Swift
探索iOS开发之旅:从初学者到专家
在这篇文章中,我们将一起踏上iOS开发的旅程,从基础概念的理解到深入掌握核心技术。无论你是编程新手还是希望提升技能的开发者,这里都有你需要的指南和启示。我们将通过实际案例和代码示例,展示如何构建一个功能齐全的iOS应用。准备好了吗?让我们一起开始吧!
|
3月前
|
安全 Swift iOS开发
Swift 与 UIKit 在 iOS 应用界面开发中的关键技术和实践方法
本文深入探讨了 Swift 与 UIKit 在 iOS 应用界面开发中的关键技术和实践方法。Swift 以其简洁、高效和类型安全的特点,结合 UIKit 丰富的组件和功能,为开发者提供了强大的工具。文章从 Swift 的语法优势、类型安全、编程模型以及与 UIKit 的集成,到 UIKit 的主要组件和功能,再到构建界面的实践技巧和实际案例分析,全面介绍了如何利用这些技术创建高质量的用户界面。
58 2
|
3月前
|
安全 数据处理 Swift
深入探索iOS开发中的Swift语言特性
本文旨在为开发者提供对Swift语言在iOS平台开发的深度理解,涵盖从基础语法到高级特性的全面分析。通过具体案例和代码示例,揭示Swift如何简化编程过程、提高代码效率,并促进iOS应用的创新。文章不仅适合初学者作为入门指南,也适合有经验的开发者深化对Swift语言的认识。
71 9

热门文章

最新文章