あれ、以前の記事でリンクしたOpenFeintのURLが
リダイレクトされて新しいページに遷移する↓
http://comeplay.gree.net/
そうだ、OpenFeintはGreePlatformに統合されたのでした。
ちなみに、be-styleのアプリではGreePlatform版ではないOpenFeintを使っています。
なので、日本語にはまだ未対応ですorz
iPhone/iPad(以下、iOS)への組み込みはAndroidとはやっぱり違っていました。
そもそも、使える機能がiOS版の方が多い!
色々使いたい誘惑を受けながらも、まずは基本の「ランキング(Leaderboard)」「実績(Achievement)」を組み込みました。
今回は、最新版(OpenFeint iOS SDK 2.12.8)を使用しました。
まずは、リファレンス(英語)です。
リファレンス :
http://support.openfeint.com/dev/readme-for-openfeint-ios-sdk-2-12-8/
うーん、英語を読むのが大変そうだ。サンプルプログラムも少し作り込んでて追うのが大変だ。
バージョンは違いますが、日本語で説明されてあるサイトがあったのでそちらで流れを把握↓
MAGENTE lab - OpenFeint 組込1−導入準備
http://www.magente.jp/modules/d3blog_2/details.php?bid=2
ただ、SDKのバージョンが違うので、こちらのサイトにある実装をそのまま適用できませんでした。
ということで、両サイトを読みながら実装しました。
流れを整理します。
--------------------------------------------------------------
(1) OpenFeintの管理画面でLeaderboardとAchievementを設定する
(2) 最新SDK(OpenFeint iOS SDK 2.12.8)を入手する
(3) SDKをXcodeのプロジェクトにインポートする
(4) Build Setting を設定して、ビルドできるか確認する
(5) 実装する
--------------------------------------------------------------
それでは、早速始めます。
(1) OpenFeintの管理画面でLeaderboardとAchievementを設定する
管理画面での操作はAndroidと同じなので以前の記事と同じ操作をします。
(2) 最新SDK(OpenFeint iOS SDK 2.12.8)を入手する
OpenFeintの管理画面から最新版のSDKをダウンロードします↓
https://api.openfeint.com/dd/downloads
(3) SDKをXcodeのプロジェクトにインポートする
GameFeedをゆくゆくは使いたいので、GameFeedを使う前提で進めていきます。
リファレンスは↓のとおり。
GameFeed導入用リファレンス(英語)
http://support.openfeint.com/dev/readme-for-openfeint-ios-sdk-2-12-8/#gamefeed
以下は、英語リファレンスをもとに実装した手順です。
・.frameworkをXcodeのプロジェクトにインポートする
ダウンロードして解凍した中から、「OpenFeint.framework」をXcodeのプロジェクトにある「Frameworks」
ディレクトリにドラッグ&ドロップします。
・解凍した中にある「OpenFeint」ディレクトリをXcodeのプロジェクトにインポートする
インポートした後、OpenFeint > resources の中で不要な機能があれば削除します。
私の場合は、アプリが縦向き限定なので「iPhone_Landscape」というディレクトリを削除しました。
・利用端末に合わせて「xxx.bundle」ファイルをインポートする
解凍した中に、5つのバンドルファイルがあります↓
OFResources_iPad.bundle
OFResources_iPhone_Landscape.bundle
OFResources_iPhone_Portrait.bundle
OFResources_iPhone_Universal.bundle
OFResources_Universal.bundle
この中から、アプリの仕様にあったものを選んでXcodeのプロジェクトにインポートします。
私の場合は「iPhone/iPadで縦向き」なので「OFResources_Universal.bundle」をインポートしました。
【注意】
バンドルファイルをインポートしないと、OpenFeintのレイアウトが崩れたりボタンが無効になったりします。
この手順を見落としていて、結構ハマりました。
・オフライン表示用xmlファイルをインポートする
最近、オフラインでもOpenFeintを表示できるようになったようです。
OpenFeintの管理画面から「openfeint_offline_config.xml」をダウンロードして、こちらもプロジェクトにインポートします↓

・Build Setting > Other Linker Flags に、「-all_load」を追加する
※「-ObjC」も追加しておきます

・Build Phases > Link Binary With Libraries に以下のフレームワークとライブラリを追加する
AddressBook
AddressBookUI
CFNetwork
CoreGraphics
CoreLocation
CoreText
Foundation
GameKit
libsqlite3.0.dylib
libz.1.2.5.dylib
MapKit
MobileCoreServices
QuartzCore
Security
SystemConfiguration
UIKit
(4) Build Setting を設定して、ビルドできるか確認する
(3)が完了した時点でビルドします。ビルドエラーが出た場合は、以下の点を確認します。
・プロジェクトにインポートするときに、ターゲット先にアプリが指定されていない
・Link Binary With Libraries で設定したフレームワークやライブラリに不足がある
・Build Settings > Build Options > Compiler for C/C++/Objective-C > Apple LLVM compiler 3.1 になっていない↓

(5) 実装する
・OpenFeintの初期化
XXXXXXXAppDelegate.mm
※拡張子を .m から .mm に変更する必要があります(.m のままだとビルドエラーになります)
【参考】Objective-C プログラミング
OpenFeintに関わる部分のみを抜粋(サンプルプログラムを参考)↓
------------------------------------------------------
#import "OpenFeint/OpenFeint.h"
@synthesize window;
@synthesize rootController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// =================== OpenFeint(ここから) ===================
window.frame = [UIScreen mainScreen].bounds;
[window addSubview:rootController.view];
[window makeKeyAndVisible];
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:UIInterfaceOrientationPortrait],
OpenFeintSettingDashboardOrientation,
@"[アプリ名(簡易名)]", OpenFeintSettingShortDisplayName,
[NSNumber numberWithBool:YES], OpenFeintSettingEnablePushNotifications,
[NSNumber numberWithBool:NO], OpenFeintSettingDisableUserGeneratedContent,
[NSNumber numberWithBool:NO], OpenFeintSettingAlwaysAskForApprovalInDebug,
#ifdef DEBUG
[NSNumber numberWithInt:OFDevelopmentMode_DEVELOPMENT], OpenFeintSettingDevelopmentMode,
#else
[NSNumber numberWithInt:OFDevelopmentMode_RELEASE], OpenFeintSettingDevelopmentMode,
#endif
self.window, OpenFeintSettingPresentationWindow,
#ifdef DEBUG
[NSNumber numberWithInt:OFDevelopmentMode_DEVELOPMENT], OpenFeintSettingDevelopmentMode,
#else
[NSNumber numberWithInt:OFDevelopmentMode_RELEASE], OpenFeintSettingDevelopmentMode,
#endif
nil
];
XXXXXXXViewController* rootViewController = [[XXXXXXXViewController alloc] init];
[rootController pushViewController:rootViewController animated:NO];
[OpenFeint initializeWithProductKey:@"[プロダクトキー]"
andSecret:@"[シークレットキー]"
andDisplayName:@"[アプリ名]"
andSettings:settings
andDelegates:nil];
// =================== OpenFeint(ここまで) ===================
return YES;
}
------------------------------------------------------
・基本情報を取得、「Leaderboard」「Achievement」を利用する
MyView.mm ※オリジナル処理をするためのUIViewを継承しています
------------------------------------------------------ここで注意があります。
// ヘッダを読み込んだり、実績とランキング用に配列を用意したり
#import "OpenFeint/OpenFeint.h"
#import "OpenFeint/OpenFeint+Dashboard.h"
#import "OpenFeint/OFAchievement.h"
#import "OpenFeint/OFAchievementService.h"
#import "OpenFeint/OFCurrentUser.h"
#import "OpenFeint/OFHighScoreService.h"
#import "OpenFeint/OFLeaderboard.h"
#import "OpenFeint/OFUser.h"
NSMutableArray* achievements; // OpenFeintの実績
NSMutableArray* leaderboards; // OpenFeintのランキング
------------------------------------------------------
基本情報を表示します↓
------------------------------------------------------
// OpenFeintのユーザー名
NSLog(@"%@", [[OFCurrentUser currentUser] name]);
// 実績の数
NSLog(@"ach count = %d", [[OFAchievement achievements] count]);
// 実績の内容を確認する
achievements = [[OFAchievement achievements] mutableCopy];
for (OFAchievement* achievement in achievements) {
OFAchievement* realAch = [OFAchievement achievement:achievement.resourceId];
NSLog(@"Achievement: %@, %d, unlocked? %@", realAch.title, realAch.gamerscore, realAch.isUnlocked ? @"YES" : @"NO");
}
// ID指定で実績が開放(unlock)されているか
NSLog(@"%@",[self IsUnlocked:@"[実績のID]"] ? @"y" : @"n");
// ランキングの数
NSLog(@"test %d", [[OFLeaderboard leaderboards] count]);
// ランキングの内容を確認する
leaderboards = [[OFLeaderboard leaderboards] mutableCopy];
for (OFLeaderboard* leaderboard in leaderboards) {
OFLeaderboard* curLeaderboard = [OFLeaderboard leaderboard:leaderboard.resourceId];
NSLog(@"leaderboard count = %@", curLeaderboard.name);
}
// ID指定でランキング用ダッシュボードを表示する
[OpenFeint launchDashboardWithHighscorePage:@"[ランキングのID]"];
------------------------------------------------------
Androidで既にOpenFeintを利用していました。
OpenFeintの管理画面ではiOS用のアプリ情報(Application Information)を追加すればよいかと思いきや、
それだけだと上記の実装でランキングと実績の一部しか取得できませんでした。
Application Information画面↓

原因は、ランキングと実績の各設定で「Starting Version」が「In Development」になっていなかったことでした。
iOSを追加した時点で「In Development」に設定されるものとされないものがあるなんて予想外でした。
プログラムに間違いが見つからない場合は、管理画面をチェックしましょう。
バージョン管理で、「In Development」が「0000.00.00」になっているかを確認↓

各ランキング、実績でiOSの「Starting Version」が「In Development」になっているかを確認。
ここで「In Development」になっていなかったことが、プログラムで取得できなかった原因でした↓

いよいよ「ランキング」「実績」を登録する処理を実装します。
------------------------------------------------------これでOpenFeintの「ランキング」と「実績」の内容を確認したり、投稿したりできるようになりました。
// ランキングに投稿する
// 参考 : http://stackoverflow.com/questions/7583906/issue-in-openfeint-when-i-call-sethighscore-function
long score = [self Float2Long:[ゲームの得点]];
[OFHighScoreService setHighScore:score forLeaderboard:@"[ランキングのID]" onSuccessInvocation:nil onFailureInvocation:nil];
// 実績を開放する
// updateProgressionComplete を100にすることで開放になる
[[OFAchievement achievement:@"[実績のID]"] updateProgressionComplete:100 andShowNotification:true];
------------------------------------------------------
ゲームらしくなってきた!