在我的 Iphone 应用程序中,我使用的是 facebook sdk 3.1。我想先重定向 facebook 登录页面。再次登录后重定向到我的应用程序。
当我没有在 iphone 的设置中登录 facebook 时,我还想从friendspickercontroller 获取 facebook 好友列表。
我正在使用此代码
Facebook登入:
-(IBAction)facebookButtonPressed:(id)sender
{
NSLog(@" hi im ");
NSArray *permissions =
[NSArray arrayWithObjects:@"user_photos", @"friends_photos",@"email", nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
if(!error)
{
NSLog(@" hi im sucessfully lloged in");
[self sessionStateChanged:session state:state error:error];
}
}];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
{
UIViewController *topViewController =
[appDelegate.naviCon topViewController];
if ([[topViewController modalViewController]
isKindOfClass:[ViewController class]]) {
[topViewController dismissModalViewControllerAnimated:YES];
}
NSLog(@"h im in state open 1111111");
{
NSLog(@"hi iam in open state9999999999999999999");
}
}
break;
case FBSessionStateClosed:
{
NSLog(@"iam in loginfailed 444444444444");
}
case FBSessionStateClosedLoginFailed:
NSLog(@"iam in loginfailed 555555555555");
NSLog(@"iam in statecloze 555555555555");
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if (error)
{
}
}
得到油炸物:
NSArray *permissions =
[NSArray arrayWithObjects:@"user_photos", @"friends_photos",@"email", nil];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler: ^(FBSession *session, FBSessionState state, NSError *error)
{
if(!error)
{
if (self.friendPickerController == nil)
{
self.friendPickerController = [[FBFriendPickerViewController alloc] init];
self.friendPickerController.title = @"Pick Friends";
self.friendPickerController.delegate = self;
}
[self.friendPickerController loadData];
//[self.friendPickerController clearSelection];
[self presentModalViewController:self.friendPickerController animated:YES];
}
}];
}
提前致谢