その後のその後

iOSエンジニア 堤 修一のブログ github.com/shu223

Facebook SDK 3.0 for iOS のサンプルを一通り試してみました

今回は従来のように github からソース一式をとってくる方式ではなく、インストールパッケージをダウンロードしてインストールする方式になったようです。
https://developers.facebook.com/ios/


で、インストールはさくっと終わったのですが、どこに何がインストールされたのかわからなかったのでもう一度インストールし直して最後に出てくるドキュメントを確認しました。

TRY IT OUT

1. Test your install; build and run the project at ~/Documents/FacebookSDK/Samples/HelloFacebookSample/HelloFacebookSample.xcodeproj

2. Check-out the tutorials available online at: https://developers.facebook.com/docs/getting-started/getting-started-with-the-ios-sdk

3. Start coding! Visit https://developers.facebook.com/ios for tutorials and reference documentation.


上記1に記載されている通り、~/Documents/FacebookSDKにインストールされます。




以下、サンプルを一通り動かしてみた中で、個人的に今後使いそうと思ったものを紹介させていただきます。


FriendPickerSample

友人一覧を表示し、ユーザーが選択した友人のリストをプロパティに保持してくれる FBFriendPickerViewController のサンプルです。



ソースを見ると、FBFriendPickerViewController を表示する部分のコードはこう実装されていました。

FBFriendPickerViewController *friendPicker = [[FBFriendPickerViewController alloc] init];
self.friendPickerController = friendPicker;

[friendPicker loadData];

// Create navigation controller related UI for the friend picker.
friendPicker.navigationItem.title = @"Pick Friends";
friendPicker.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] 
                                                  initWithTitle:@"Done" 
                                                  style:UIBarButtonItemStyleBordered 
                                                  target:self 
                                                  action:@selector(doneButtonWasPressed:)];
friendPicker.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] 
                                                 initWithTitle:@"Cancel" 
                                                 style:UIBarButtonItemStyleBordered 
                                                 target:self 
                                                 action:@selector(cancelButtonWasPressed:)];

// Make current.
[self.navigationController pushViewController:friendPicker animated:YES];


ユーザーが選択した友達のリストをプロパティから取得する部分のコードはこんな感じです。

for (id<FBGraphUser> user in self.friendPickerController.selection) {
    if ([text length]) {
        [text appendString:@", "];
    }
    [text appendString:user.name];
}

PlacePickerSample

FBPlacePickerViewController のサンプル。


そのままビルドして起動すると



こんな感じでシアトルのスポット一覧が出てきてイマイチありがたみがわかりづらいのですが、PPViewController.m の reflesh メソッド内の

[self searchDisplayController:nil shouldReloadTableForSearchScope:SampleLocationSeattle];

ここを、

[self searchDisplayController:nil shouldReloadTableForSearchScope:SampleLocationGPS];

こう書き換えると現在位置周辺のスポット一覧が出てくるようになるので若干新SDKのありがたみが増すかもしれません。



Hackbook

いろんなサンプルが入ったデモプロジェクトです。


目新しいものとしては、招待ダイアログのデモがありました。



アプリを使っている人のみをリストに出す、アプリを使ってない人のみをリストに出す、など様々なパターンのサンプルがあります。


写真のアップロードのデモも入っていたのですが、こちらは新しい写真投稿用ダイアログとかはなく、ボタンをタップすると勝手に写真がアップされてしまうという残念なサンプルでした・・・


ProfilePictureSample

FBProfilePictureView のサンプル。



切り抜きができますよ、ということ以外の違いはこのサンプルからはわからず。FBProfilePictureView のヘッダみてみると、userID プロパティと pictureCropping プロパティぐらいしかないので、userID に値をセットするだけで非同期でアイコン画像を取ってくる、的なことが売りなビュークラスなのかも。(※詳細未確認)


その他

SDK 3.0 の What's New はこちらにまとまっています。
https://developers.facebook.com/features/whats-new-ios-sdk-3/