約2週間前に最近のFBSDKに更新しました。これが私がやった方法です:
//FB recommends to put these two in the app delegate in their sample apps but you can place them other places
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions", nil];
return [FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
NSLog((@"session.state is %d",session.state));
if(session.state==513){
[AppPrefererences sharedAppPrefererences].faceBookLoggedIn=YES;
NSLog((@"facebookLogin pref has been set to yes from inside appDelegate"));
}
else{
[AppPrefererences sharedAppPrefererences].faceBookLoggedIn=NO;
}
}];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// FBSample logic
// We need to handle URLs by passing them to FBSession in order for SSO authentication
// to work.
return [FBSession.activeSession handleOpenURL:url];
}
//Then whereever you want to initiate the log in (i use mine in a tableView)
AppDelegate *appDelegate =(AppDelegate*) [[UIApplication sharedApplication]delegate];
if (![appDelegate openSessionWithAllowLoginUI:NO]) {
[appDelegate openSessionWithAllowLoginUI:YES];
facebookLoginLabel.text=@"Facebook Log Out";
[AppPrefererences sharedAppPrefererences].faceBookEnabled=YES;
}
else{
facebookLoginLabel.text=@"Facebook Log In";
[AppPrefererences sharedAppPrefererences].faceBookLoggedIn=NO;
[FBSession.activeSession closeAndClearTokenInformation];
}
そして、あなたが投稿したいところはどこでもあなたはこれをします:
[FBRequestConnection startForPostStatusUpdate:@"any thing you want to post"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error){}];
また、FBLoginViewDelegateを設定することも忘れないでください
ご不明な点がございましたらお知らせください。それが役に立てば幸い!