3

I am able to get the user profile permissions if user has set facebook account in his iPhone settings. For this I have used following code:

if(!_accountStore)
    _accountStore = [[ACAccountStore alloc] init];

ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                       options:@{ACFacebookAppIdKey: @"app_id", ACFacebookPermissionsKey: @[@"email"]}
                                    completion:^(BOOL granted, NSError *error) {
                                        if(granted){
                                            NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
                                            _facebookAccount = [accounts lastObject];
                                            NSLog(@"Success");

                                            [self me];
                                        }else{
                                           NSLog(@"go to iphone settings");

                                        }
                                    }];






-(void)me 
   {

    NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];

    SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                              requestMethod:SLRequestMethodGET
                                                        URL:meurl
                                                 parameters:nil];

    merequest.account = _facebookAccount;

    [merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        NSLog(@"%@", meDataString);

    }];   
}

If user hasn't set his facebook account then control will move to else part i.e. go to iphone settings. In this else part I want to open the facebook login page so that user will be able to login in his facebook account without going to iPhone settings. SO how could we open the facebook login via SDK. Please help me out from this issue.

Thanks in advance.

4

1 回答 1

1

在这种情况下,如果您不使用用户帐户(如果他/她没有在 iOS 设置中设置它),您需要实现 Facebook SDK ( https://developers.facebook.com/ ios/ ) 在您的应用程序上。这很简单,只需按照以下步骤(https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/)。

之后,您可以使用FBSession's方法+openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:执行用户登录。

确实,在我的应用程序中,我什至没有尝试使用 ApplerequestAccessToAccountsWithType:options:completion:;使用最新的 Facebook SDK 登录用户,默认行为是:

  1. 尝试使用 iOS 设置上的用户帐户设置登录;
  2. 如果没有找到帐户,尝试打开 Facebook 应用程序以请求登录/权限;
  3. 如果设备上未安装 Facebook 应用程序,它会在 Safari 上打开 Facebook,作为后备。
于 2013-06-06T14:31:59.497 回答