2016-12-02 76 views
-1

我想使用Facebook应用程序,如果它安装在通过我的iOS应用程序中的Facebook登录设备上。现在它重定向到Safari浏览器,无论是否安装了应用程序?Facebook sdk不使用已安装的应用程序进行登录iOS 10.0

任何帮助,将不胜感激。

谢谢。

+0

NSURL * url = [NSURL URLWithString:@“fb:// profile/”]; [[UIApplication sharedApplication] openURL:url]; if([[UIApplication sharedApplication] canOpenURL:nsurl]){[UIApplication sharedApplication] openURL:nsurl]; } else { //像往常一样打开网址 } –

回答

0

Facebook登录政策已更改。没有错,iOS的10

参考 - https://developers.facebook.com/docs/facebook-login/ios

你必须给行为,以原生像下面。

login.loginBehavior = FBSDKLoginBehaviorNative; 

确保1件事,如果用户没有Facebook应用程序,那么。

所以更好使用。这将仅在应用程序内的登录视图控制器上打开Facebook登录页面。

login.loginBehavior = FBSDKLoginBehaviorWeb; 

示例代码

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 

    login.loginBehavior = FBSDKLoginBehaviorNative; 

    [login 
    logInWithReadPermissions: @[@"public_profile",@"email"] 
    fromViewController:self 
    handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
     if (error) { 
      NSLog(@"Process error"); 

     } 
     else if (result.isCancelled) 
     { 
      NSLog(@"Cancelled"); 
     } 
     else { 
      if ([FBSDKAccessToken currentAccessToken]) { 
       [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email, name"}] 
        startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
         if (!error) { 
          NSLog(@"fetched user:%@", result); 

         } 
        }]; 
      } 
     } 
    }]; 

只需点击FBSDKLoginBehaviorNative,它会引导你到FacebookLoginManager.h

正确阅读和理解。

typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior) 
{ 
    /*! 
    @abstract This is the default behavior, and indicates logging in through the native 
    Facebook app may be used. The SDK may still use Safari instead. 
    */ 
    FBSDKLoginBehaviorNative = 0, 
    /*! 
    @abstract Attempts log in through the Safari or SFSafariViewController, if available. 
    */ 
    FBSDKLoginBehaviorBrowser, 
    /*! 
    @abstract Attempts log in through the Facebook account currently signed in through 
    the device Settings. 
    @note If the account is not available to the app (either not configured by user or 
    as determined by the SDK) this behavior falls back to \c FBSDKLoginBehaviorNative. 
    */ 
    FBSDKLoginBehaviorSystemAccount, 
    /*! 
    @abstract Attempts log in through a modal \c UIWebView pop up 

    @note This behavior is only available to certain types of apps. Please check the Facebook 
    Platform Policy to verify your app meets the restrictions. 
    */ 
    FBSDKLoginBehaviorWeb, 
}; 
+0

您好@Hasya,感谢您的回复,但我已经尝试过您的代码,但无法通过本机iOS应用程序登录(如果已安装)。我想要做的就好像应用程序已安装,然后它将打开Facebook应用程序,否则重定向到浏览器 – puja

相关问题