我的应用程序委托中有此代码:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
self.openedURL = url;
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
如何从 UIViewController 调用它?
编辑:
- (IBAction)authButtonAction:(id)sender {
/*
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];*/
// The user has initiated a login, so call the openSession method
// and show the login UX if necessary.
//[appDelegate openSessionWithAllowLoginUI:YES];
// If the user is authenticated, log out when the button is clicked.
// If the user is not authenticated, log in when the button is clicked.
if (FBSession.activeSession.isOpen) {
[FacebookDialogueViewControllerDelegate closeSession];
} else {
// The user has initiated a login, so call the openSession method
// and show the login UX if necessary.
[FacebookDialogueViewControllerDelegate openSessionWithAllowLoginUI:YES];
}
}
...视图控制器然后有这个:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}