私のiPhoneアプリでは、FacebookSDK3.1を使用しています。最初にFacebookのログインページをリダイレクトしたい。ログイン後、アプリにリダイレクトします。
また、iPhoneの設定でFacebookにログインしていないときに、friendspickercontrollerから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];
}
}];
}
前もって感謝します