我想使用Facebook應用程序,如果它安裝在通過我的iOS應用程序中的Facebook登錄設備上。現在它重定向到Safari瀏覽器,無論是否安裝了應用程序?Facebook sdk不使用已安裝的應用程序進行登錄iOS 10.0
任何幫助,將不勝感激。
謝謝。
我想使用Facebook應用程序,如果它安裝在通過我的iOS應用程序中的Facebook登錄設備上。現在它重定向到Safari瀏覽器,無論是否安裝了應用程序?Facebook sdk不使用已安裝的應用程序進行登錄iOS 10.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,
};
您好@Hasya,感謝您的回覆,但我已經嘗試過您的代碼,但無法通過本機iOS應用程序登錄(如果已安裝)。我想要做的就好像應用程序已安裝,然後它將打開Facebook應用程序,否則重定向到瀏覽器 – puja
NSURL * url = [NSURL URLWithString:@「fb:// profile/」]; [[UIApplication sharedApplication] openURL:url]; if([[UIApplication sharedApplication] canOpenURL:nsurl]){[UIApplication sharedApplication] openURL:nsurl]; } else { //像往常一樣打開網址 } –