天天看點

【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.正确制作證書後,有個這樣的檔案:

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

輕按兩下此檔案,彈出organizer-devices界面,連接配接你的真機iphone、ipad或者touch,然後左側可以看到如下圖:

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

右側的綠色小燈表示可以正常使用,這個小燈如果是黃色,那就說明你的證書有問題,可能是此手機的udid沒有在證書内等原因;

3.確定真機正常後,點選你的項目,右側點選project點選build settings頁面,然後code signing下設定code signing identity為你的證書,如下圖:

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

4.點選你的項目,右側點選targets,點選info頁面下的設定bundle identifier,這個bundle identifier在你制作證書的過程中就會了解到,如下圖:

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

ok,可以編譯運作你的項目到真機中了;

—————遊戲接入gamecenter 指南

1.    itunes connect 設定

首先,申請一個應用程式,不必送出.目地是為了得到bundle id.

然後設定一下工程中info.plist的bundle identifier使之與itunes connect中的bundle id相同,否則當你嘗試登入gamecenter的時候,會提示一個不支援gamecenter的錯誤.

申請完畢,打開你剛申請的application,點選manage game center選項.

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

進入後點選enable game center使你的game center生效.

接下來就可以設定自己的leaderboard和achievements.

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

2.    leaderboard設定

leaderboard縱觀圖如下所示.

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

1.sort order: leaderboard中的内容是以升序還是降序排列.

2.score format type:分數的類型.

3.*categories:leaderboard的一個分數榜,這個可以建立多個,比如遊戲可以分為easy,normal,hard三個難度,每個難度一個榜.

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

*設定完成後儲存,完成了一個 leaderboard的設定.我們可以根據需要添加多個 leaderboard.

4.**score format location: leaderboard支援的語言.

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

**可以支援多種語言,每支援一種語言,需要完成一個上述操作.

這個時候右下角會出現save change按鈕,點選完成leaderboard的設定.

你可以根據需要随時更改你的leaderboard,操作與上述内容類似.

3.    achievements設定

achievements界面内容比較少,點選左上角的add new achievement,打開如下圖所示的achievements建立界面.

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

    hidden:表示該成就為解鎖前玩家是否可見.

    achievement id:程式通過這個屬性來識别成就.

    *achievement localization:該成就支援的語言.

    *achievement localization設定如下圖所示.

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

*其中,成就的image必須是512x512,72dpi的.

一切設定完成後,點選save change按鈕即完成一個成就的設定.

4.總體功能

4.1 對game center支援判斷

1

2

3

4

5

6

7

8

9

- (bool) isgamecenteravailable  

  {  

      class gcclass = (nsclassfromstring(@"gklocalplayer"));  

       nsstring *reqsysver = @"4.1";  

       nsstring *currsysver = [[uidevice currentdevice] systemversion];  

       bool osversionsupported = ([currsysver compare:reqsysver options:nsnumericsearch] != nsorderedascending);  

      return (gcclass && osversionsupported);  

   }

4.2使用者登入

10

11

12

13

14

15

16

17

- (void) authenticatelocalplayer  

   {  

       [[gklocalplayer localplayer] authenticatewithcompletionhandler:^(nserror *error){  

          if (error == nil) {  

              //成功處理  

              nslog(@"成功");  

              nslog(@"1--alias--.%@",[gklocalplayer localplayer].alias);  

               nslog(@"2--authenticated--.%d",[gklocalplayer localplayer].authenticated);  

              nslog(@"3--isfriend--.%d",[gklocalplayer localplayer].isfriend);  

              nslog(@"4--playerid--.%@",[gklocalplayer localplayer].playerid);  

             nslog(@"5--underage--.%d",[gklocalplayer localplayer].underage);  

         }else {  

              //錯誤處理  

             nslog(@"失敗  %@",error);  

          }  

     }];  

  }

對于開發者來說,game center必須經過測試才能上線,沒有上線的程式在測試環境中登入時會出現sandbox提示.如圖.

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

4.3使用者變更檢測

由于4.0以後系統支援多任務,玩家的機器有可能被不同的玩家接觸,導緻game center上的使用者發生變化,當發生變化的時候,程式必須在遊戲中通知玩家.

18

19

20

- (void) registerforauthenticationnotification  

       nsnotificationcenter *nc = [nsnotificationcenter defaultcenter];  

       [nc addobserver:self  

              selector:@selector(authenticationchanged)  

                   name:gkplayerauthenticationdidchangenotificationname  

                object:nil];  

   }  

  - (void) authenticationchanged  

       if ([gklocalplayer localplayer].isauthenticated)  

       {  

           ;// insert code here to handle a successful authentication.  

       }  

      else  

      {  

          ;// insert code here to clean up any outstanding game center-related classes.  

     }  

5.對leaderboard進行操作

5.1上傳一個分數

- (void) reportscore: (int64_t) score forcategory: (nsstring*) category  

     gkscore *scorereporter = [[[gkscore alloc] initwithcategory:category] autorelease];  

      scorereporter.value = score;  

       [scorereporter reportscorewithcompletionhandler:^(nserror *error) {  

          if (error != nil)  

          {  

             // handle the reporting error  

              nslog(@"上傳分數出錯.");  

             //if your application receives a network error, you should not discard the score.  

             //instead, store the score object and attempt to report the player’s process at  

              //a later time.  

          }else {  

             nslog(@"上傳分數成功");  

         }  

當上傳分數出錯的時候,要将上傳的分數存儲起來,比如将skscore存入一個nsarray中.等可以上傳的時候再次嘗試.

5.2下載下傳一個分數

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

//gkscore objects provide the data your application needs to create a custom view.  

//your application can use the score object’s playerid to load the player’s alias.  

  //the value property holds the actual value you reported to game center. the formattedvalue  

  //property provides a string with the score value formatted according to the parameters  

  //you provided in itunes connect.  

  - (void) retrievetoptenscores  

     gkleaderboard *leaderboardrequest = [[gkleaderboard alloc] init];  

    if (leaderboardrequest != nil)  

     {  

        leaderboardrequest.playerscope = gkleaderboardplayerscopeglobal;  

        leaderboardrequest.timescope = gkleaderboardtimescopealltime;  

        leaderboardrequest.range = nsmakerange(1,10);  

         leaderboardrequest.category = @"ts_lb";  

         [leaderboardrequest loadscoreswithcompletionhandler: ^(nsarray *scores, nserror *error) {  

             if (error != nil){  

                 // handle the error.  

                 nslog(@"下載下傳失敗");  

             }  

            if (scores != nil){  

                // process the score information.  

                nslog(@"下載下傳成功....");  

               nsarray *tempscore = [nsarray arraywitharray:leaderboardrequest.scores];  

                 for (gkscore *obj in tempscore) {  

                   nslog(@"    playerid            : %@",obj.playerid);  

                    nslog(@"    category            : %@",obj.category);  

                    nslog(@"    date                : %@",obj.date);  

                    nslog(@"    formattedvalue    : %@",obj.formattedvalue);  

                     nslog(@"    value                : %d",obj.value);  

                    nslog(@"    rank                : %d",obj.rank);  

                   nslog(@"**************************************");  

                 }  

        }];  

    }  

}

說明:

1)    playerscope:表示檢索玩家分數範圍.

2)    timescope:表示某一段時間内的分數

3)    range:表示分數排名的範圍

4)    category:表示你的leaderboard的id.

5.3玩家資訊互動

game center最重要的一個功能就是玩家互動.是以,必須檢索已經登入玩家的好友資訊.根據自己的需要做出設定,比如,可以與好友比較分數,或者好友排行榜等.

//檢索已登入使用者好友清單

- (void) retrievefriends  

{  

     gklocalplayer *lp = [gklocalplayer localplayer];  

     if (lp.authenticated)  

         [lp loadfriendswithcompletionhandler:^(nsarray *friends, nserror *error) {  

             if (error == nil)  

            {  

                 [self loadplayerdata:friends];  

            }  

            else  

                ;// report an error to the user.  

上面的friends得到的隻是一個身份清單,裡面存儲的是nsstring,想要轉換成好友id,必須調用- (void) loadplayerdata: (nsarray *) identifiers方法,該方法得到的array裡面存儲的才是gkplayer對象.如下

/*

   whether you received player identifiers by loading the identifiers for the local player’s

  friends, or from another game center class, you must retrieve the details about that player

  from game center.

   */  

  - (void) loadplayerdata: (nsarray *) identifiers  

     [gkplayer loadplayersforidentifiers:identifiers withcompletionhandler:^(nsarray *players, nserror *error) {  

         if (error != nil)  

         {  

              // handle the error.  

        }  

         if (players != nil)  

            nslog(@"得到好友的alias成功");  

             gkplayer *friend1 = [players objectatindex:0];  

            nslog(@"friedns---alias---%@",friend1.alias);  

            nslog(@"friedns---isfriend---%d",friend1.isfriend);  

            nslog(@"friedns---playerid---%@",friend1.playerid);  

至此,leaderboard功能介紹完畢

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提供了該功能.當然,你也可以自己在程式中完成,畢竟玩家不可能時刻處于線上狀态.

37

38

39

40

41

42

- (nsarray*)retrieveachievmentmetadata  

      //讀取成就的描述  

      [gkachievementdescription loadachievementdescriptionswithcompletionhandler:  

        ^(nsarray *descriptions, nserror *error) {  

           {  

                // 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也分享一下如何模仿官方橫幅提示樣式的方法和代碼:

type one error類将展示類似于ios 5所呈現的通知内容,但代碼需獲悉成就标題和描述是什麼。為實作這點,你需要嵌入“showscompletionbanner”目标。

gkachievementdescription目标的優點是它們已根據使用者語言設定進行本土化,是以采用此方式不存在任何本土化問題。

其弊端在于你無法隻加載一個成就描述,你需要加載所有内容。我認為進行此操作的最佳時間是使用者已在應用上認證game center,此時你需要通過異步調用獲得這些消息。值得欣慰的是,蘋果在此設有api調用,我将此放置在使用者認證通路的completionhandler中。

若你采用ray wenderlich網站的代碼,那麼你就既能夠運用此方法,又擁有新方法。将nsmutabledictionary * self.achievementsdescdictionary添加至所有處理遊戲game center代碼的類(遊戲邦注:它會在随後的體驗中存儲成就資料)。

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

- (void)authenticatelocaluser {  

if (!gamecenteravailable) return;  

nslog(@”authenticating local user…”);  

if ([gklocalplayer localplayer].authenticated == no) {  

[[gklocalplayer localplayer]  

authenticatewithcompletionhandler:^(nserror *error) {  

if([gklocalplayer localplayer].isauthenticated){  

[self retrieveachievmentmetadata];         //here is the new code  

//here is the new method.  

- (void) retrieveachievmentmetadata  

self.achievementsdescdictionary = [[nsmutabledictionary alloc] initwithcapacity:2];  

[gkachievementdescription loadachievementdescriptionswithcompletionhandler:  

^(nsarray *descriptions, nserror *error) {  

if (error != nil) {  

nslog(@"error %@", error);  

if (descriptions != nil){  

for (gkachievementdescription* a in descriptions) {  

[achievementsdescdictionary setobject: a forkey: a.identifier];  

“retrieveachievmentmetadata”方法會初始化所有資訊庫,然後調用遊戲所有成就描述,進行循環,将它們添加至資訊庫。這屬于異步調用,是以不應減緩遊戲或項目的啟動。  

現在我們握有各成就的标題和描述,是以能夠修改原始代碼創造ios 4/5的善意通知,其将通過type one error代碼連續展示所有成就。  

- (void)reportachievement:(nsstring *)identifier  

percentcomplete:(double)percentcomplete {  

gkachievement* achievement = [[gkachievement alloc]  

initwithidentifier:identifier];  

achievement.percentcomplete = percentcomplete;  

if (percentcomplete == 100.0) {  

//show banners manually  

gkachievementdescription *desc = [achievementsdescdictionary objectforkey:identifier]; //update pull achievement description for dictionary  

[[gkachievementhandler defaulthandler] notifyachievement:desc];  //display to user  

[achievementstoreport addobject:achievement];    //queue up the achievement to be sent  

[self save];  

if (!gamecenteravailable || !userauthenticated) return;  

[self sendachievement:achievement];   //try to send achievement  

[achievementstoreport removeobject:achievement];   //remove achievement from queue.  

nslog(@”achievement failed to send… will try again \  

later.  reason: %@”, error.localizeddescription);  

如果你想讓成就中顯示為你在itunes connect中設定成就的自定義圖檔,首先将通知部分代碼修改成如下代碼:

gkachievementdescription *desc = [achievementsdescdictionary objectforkey:identifier];  

[desc loadimagewithcompletionhandler:^(uiimage *image, nserror *error) {  

if (error == nil)  

[[gkachievementhandler defaulthandler] setimage:desc.image];   //if image found, updates the image to the achievement image.  

[[gkachievementhandler defaulthandler] notifyachievement:desc];  

使用以上方式預設為橫屏顯示成就通知,如果想換成豎屏提示,那麼這裡himi給出參考代碼:

在“gkachievementhandler”類中找到“notifyachievement”,更新為:

- (void)notifyachievement:(gkachievementdescription *)achievement  

gkachievementnotification *notification = [[gkachievementnotification alloc] initwithachievementdescription:achievement];  

notification.frame = kgkachievementframestart;  

notification.handlerdelegate = self;  

//adjusting rotation.  

if ([[uiapplication sharedapplication] statusbarorientation] == uiinterfaceorientationlandscapeleft) {  

notification.transform = cgaffinetransformrotate(notification.transform, degreestoradian(-90));  

notification.transform = cgaffinetransformrotate(notification.transform, degreestoradian(90));  

[_queue addobject:notification];  

if ([_queue count] == 1)  

[self displaynotification:notification];  

截圖如下:

【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;
【IOS開發必備指南合集】申請企業級IDP、真機調試、遊戲接入GAMECENTER 指南(實作仿官方的成就提示框)、遊戲接入OPENFEINT指南;

openfeint 是很多iphone遊戲開發者都要用到的社群功能;

一、openfeint中的leaderboards 和achievement的一點體會

1.資料送出的格式

最近想向自己 的遊戲中添加點openfeint功能,使用的時候發現,openfeint的功能雖然比較多,也比較強大,但是,有些地方還是不太如人意。我遊戲中的分 數有一項是float型的資料,可是當我送出的時候,發現openfeint的線上排名隻支援整數形式的資料,改變了官方的api送出之後,伺服器那邊仍 自動轉換成了整型的資料。我在論壇上求證了一下,雖然沒有結論,但我認為openfeint高分排行榜僅支援整型的資料。

2.資料送出的方法

[ofhighscoreservice sethighscore:你送出的分數 forleaderboard:@”分數項的id” onsuccess:ofdelegate() onfailure:ofdelegate()]; //送出高分,如果函數無效,請引入#import “ofhighscoreservice.h”

通過上面那個函數,就可以向伺服器提 交資料,其中你要送出的分數,無論是什麼類型,最後都會轉換成整型的資料,可以參見上一條資訊。而分數項id,則是你在申請laderboards的時候 openfeint配置設定給你的一個數字。後面兩個參數,應該不需要改變,我沒有嘗試過做其他的動作,有興趣和想法的朋友,可以嘗試象@selector那 樣使用它。

[ofachievementservice unlockachievement: @”成就id” onsuccess: ofdelegate() onfailure: ofdelegate()];//解鎖成就,如果函數無效,請引入#import “ofachievementservice.h”

這個函數的功能是解鎖成就,當你在遊戲過程中達到某一個要求時,就可以解鎖你在openfeint上預設的成就。

例如:

生存遊戲中:if (生存時間 > 100s )  { 調用上面的函數解鎖你自己預設的成就; }

jump遊戲中:if ( 高度 > 10000m )  { 調用上面的函數解鎖你自己預設的成就; }

3.網絡對分數送出的影響

網絡暢通的情況下,調用上述函數送出分數(最高分數被重新整理時) 可以成功,并且解鎖成就并不會反複出現解鎖提示。好吧,既然這個可以完成我們的要求,那麼這裡就不是重點。

網絡不通的情況下,就會出現一點問題:

在闡明問 題之前,我想先說一下我對openfeint的資料存儲的了解或者說感覺。使用penfeint的時候,在documents目錄下會生成兩個檔案,一個 fakekeychain.plist,據我觀察,這裡面存放的就是我們在openfeint裡為這個遊戲申請的product key和product secret,而且secret經過了加密處理。另一個檔案則是feint-offline, 這個檔案是無法打開的,在windows用記事本打開也是一堆亂碼,也許有其他的辦法,不過我沒有找到。我對于這個檔案的用途猜測是,這個檔案用來存檔玩 家的一些資訊,比如玩家名和分數等,這個檔案我暫時叫它為“本地隐 藏資訊表”吧。

問題來鳥,在沒有網絡的情況下,取得了一個分數,然後第一次調用分數送出函數,會提示你得 到了一個高分,存儲在本地(我感覺就在本地隐藏資訊表中), 問題出現了!當你這時連接配接網絡,分數并不會自動送出,而你自己手動送出(比如點選一個按鈕,按鈕的功能是送出最高分數)也沒有任何的效果。

而 在官方文檔中有這樣一q&a:

q:what happens to a high score when a player is offline?

a:as os openfeint 2.1 high scoreare queued for submission when the player is offline and submitted when next he’s online again.

q:if a user says no to using openfeint the first time,is there a way that user can change his or her mind to allow openfeint in the future?

a:when you deny openfeint it will prompt you to approve/deny again when you open the dashboard([openfeint launchdashboard]).it will not prompt you on the next app bootup,or submitting any requests.only when you open the dashboard.

也就是說,送出失敗,于是我做了個試驗,在有網絡的情況下,送出一個分數100,隻顯示 一次,第二次送出100時,沒有提示。然後送出101,有提示,第二次送出101,沒有提示。說明了本地隐藏資訊表中還存儲了一個最高分數的送出次數和送出許可,使用一次送出分數的函數,這些内 容就會改變,隻有新送出的分數比原來存儲的分數大時,本地隐藏資訊 表才會允許你向openfeint正式送出,否則,無效,感覺上和retain與release有點像。也就時說,最高的分數在送出的時 候,沒有網絡,就等于失敗,這裡應該算是openfeint的一個小bug吧。也是我遇到問題的所在,沒找到什麼解決辦法,大夥有經驗的可以提出來。

用 個簡單的圖來形容下吧。

無網絡->得到新高分->存儲在本地->聯網後->不自動上傳最高分。

順 便說下成就的送出,沒有網絡,不可解鎖成就,也沒有存在本地的提示,聯網後,同樣也不自動解鎖,隻有再一次達到條件(方才例子中的if成立)時,才會再次 解鎖。

以上,是我的部分openfeint基礎使用的經驗,也許是我的方法不正确,也許有别的解決辦法,我能提供給大家的幫助, 先這麼多了。

二、 openfeint的設定(2.4.8版)

以下步驟是假設你從沒安裝過openfeint,如果有,請将以 前老版本的openfeint從機器中删除,并從project中删除所有與openfeint有關的東西,然後,你可以按下面的步驟來做了。

1. 從官網下載下傳一個最新版本的沒有解壓的openfeint sdk。

2.将openfeint檔案夾拖入你的project中。

3. 設定info

a.打開project的info,選中build欄,将configuration設定成all configuration

b.将other linker flags一項的值設定成 -objc  區分大小寫

c.将call c++ default ctors/dtors in objective-c項的選成yes(這一步我沒有設定,不知道是什麼意思,英文原文如下:ensure ‘call c++ default ctors/dtors in objective-c’ is checked under the ‘gcc 4.2 – code generation’ section)

d.設定一個預設的值gcc_objc_call_cxx_cdtors 為 yes(這一步我也沒有設定)

4.引入frameworks

需要引入的frameworks 有,foundation,uikit,coregraphics,quartcore,security,systemconfiguration,libsql3.0 dylie,libz.1.2.3.dylib這些是官方給出需要引入的frameworks,根據幫我搭建工程的前輩說,必須要引入 corelocation.framework    cfnetwork.framework   mapkit.framework

5.必須在你的   .pch   檔案中引入#import “openfeintprefix.pch”

6.将你所有使用openfeint功能的函數改為  .mm  檔案

我能想到的就這些了,還有什麼問題,大家可以互相讨論。

三、openfeint的注冊

openfeint的注冊并不難,能看懂 文檔的水準基本就可以了,也可以配合翻譯軟體來弄。

2.選右上角的 developers一項,跳轉到的新界面。

3.點選本頁面的右上角的login會進入登陸界面,選擇右上角的 sign up進行一個簡單注冊,本頁右下角有一個教學的視訊,告訴你如何使用openfeint的基礎功能。

4.簡單注冊界面,填寫完成後跳轉到一個新的界面,點選dive in 進入你自己的openfeint裡。

5.進入自己的openfeint了,需要進行一個prepare for submission的申請,這個可以讓你的openfeint有效,否則,你隻能使用test user 進行測試。在app home中,可以看到自己的client id 這個是用來提問用的,以及最重要的product key和product secret,這兩項是用來識别你的程式獨有的openfeint的。

6.還需要一個你注冊時使用的郵箱認證。進入自己的郵箱就能看到 了。

7.想通過openfeint的稽核,還需要完善一個ipurchase的填寫,在basic features/ipurchase裡面填寫,*項必須要有内容。

8.完成上面這些,你就可以設定自己的laderboards和 achievement了,還有更多的challenge等。

                                 ——以上為himi的經驗總結以及參考資料,希望對大家有幫助;