2014/04/22

[Facebook][iOS][Objective-C]FBRequestConnectionのクラスメソッドでかえってきた値をnil化する方法について

Objective-Cを使って、facebookの情報を問い合わせるときがあります。

例:写真情報の取得

//albumのid
NSString *albumid;
[FBRequestConnection
    startWithGraphPath:[NSString stringWithFormat:@"/%@/photos",albumid],
    completionHandler:^(FBRequestConnection *connection,id result,NSError *error){
    NSLog(@"%@",result);
}];
例:アルバム情報の取得
[FBRequestConnection
    startWithGraphPath:@"/me/albums"
    completionHandler:^(FBRequestConnection *connection,id result,NSError *error){
    NSLog(@"%@",result);
}];
れ、これらのプログラムですが、問い合わせ中は、再度、上記のプログラムを実行してほしくないときがあります。

そんなときは、下のように、すればいいのかなと。
FBRequestConnection *fBRequestConnection;
if(fBRequestConnection == nil){
  fBRequestConnection = [FBRequestConnection
    startWithGraphPath:@"/me/albums"
    completionHandler:^(FBRequestConnection *connection,id result,NSError *error){
      NSLog(@"%@",result);
      fBRequestConnection = nil;
  }];
}
FBRequestConnectionのclass methodのセクションを読むと、返り値がFBRequestConnectionだったりするので、それを一度、設定して、nilじゃーないときは、問い合わせをしないようにしています。

iOS6のARCではうまくいきましたが、リファレンスカウンタ方式だとうまくいくかわからないっす。

0 コメント:

コメントを投稿