[英]Facebook native login is not opening facebook app even if it's installed in device?
i have followed every step described in the docs of facebook-iso-sdk 4.8.0 for iOS 9, but still couldn't preform app switch on "login-with-facebook" in my app, even if facebook app is already installed. 我已经按照facebook-iso-sdk 4.8.0 for iOS 9的文档中描述的每个步骤进行了操作,但仍然无法在我的应用程序中使用“login-with-facebook”进行应用程序切换,即使已经安装了facebook app。
As you can see in screen shot below i have modified info.plist, but still can't get native app switch to work. 正如您在下面的屏幕截图中看到的,我已经修改了info.plist,但仍然无法让本机应用程序切换工作。
I have also double checked for typo-mistakes in info.plist value. 我还检查了info.plist值中的错字错误。 and i can assure you they are correct.
我可以向你保证他们是对的。
Here is my code :- 这是我的代码: -
if (![AppDelegate SharedInstance].login) {
[AppDelegate SharedInstance].login = [[FBSDKLoginManager alloc] init];
}
[AppDelegate SharedInstance].login.loginBehavior = FBSDKLoginBehaviorNative;
[[AppDelegate SharedInstance].login logInWithReadPermissions:@[@"public_profile",@"email",@"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
}
else if (result.isCancelled)
{
// Handle cancellations
}
else
{
NSLog(@"result.grantedPermissions == %@",result.grantedPermissions);
if (result.token)
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, email, first_name, last_name"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [result objectForKey:@"id"]];
[dictFacebookDetail addEntriesFromDictionary:result];
[dictFacebookDetail setObject:userImageURL forKey:@"profilepic"];
NSLog(@"facebook login result --- %@",dictFacebookDetail);
[self performSelectorInBackground:@selector(CheckFacebookUser:) withObject:dictFacebookDetail];
}
}];
}
}
}];
What am i missing ? 我错过了什么?
I have found a solution, but you should change something in FBSDKLogin pod. 我找到了解决方案,但您应该在FBSDKLogin pod中进行更改。 I was debugging the Pod and I realized that Facebook ask in the class
FBSDKServerConfiguration
for the server configuration for the app. 我正在调试Pod,我意识到Facebook在类
FBSDKServerConfiguration
询问应用程序的服务器配置。 It returns a JSON with some information to configure the Pod for our app. 它返回一个带有一些信息的JSON,以便为我们的应用程序配置Pod。 I realized that by default the JSON returns this dictionary:
我意识到默认情况下JSON返回这个字典:
"ios_sdk_dialog_flows" = {
default = {
"use_native_flow" = 0;
"use_safari_vc" = 1;
};
message = {
"use_native_flow" = 1;
};
};
By default the use_native_flow
is 0, so when it saves the information in userDefaults
for the next app launches. 默认情况下,
use_native_flow
为0,因此当它将信息保存在userDefaults
以便下次启动应用程序时。 So, when the app calls FBSDKLoginMananger
login method and checks for the loginBehaviour in this method, the variable useNativeDialog
returns NO. 因此,当应用程序调用
FBSDKLoginMananger
登录方法并在此方法中检查loginBehaviour时,变量useNativeDialog
将返回NO。 So the switch uses the next case. 所以交换机使用下一个案例。
case FBSDKLoginBehaviorBrowser:
- (void)logInWithBehavior:(FBSDKLoginBehavior)loginBehavior
{
.
.
...
switch (loginBehavior) {
case FBSDKLoginBehaviorNative: {
if ([FBSDKInternalUtility isFacebookAppInstalled]) {
[FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *loadError) {
BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];
if (useNativeDialog && loadError == nil) {
[self performNativeLogInWithParameters:loginParams handler:^(BOOL openedURL, NSError *openedURLError) {
if (openedURLError) {
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors
formatString:@"FBSDKLoginBehaviorNative failed : %@\nTrying FBSDKLoginBehaviorBrowser", openedURLError];
}
if (openedURL) {
completion(YES, FBSDKLoginManagerLoggerAuthMethod_Native, openedURLError);
} else {
[self logInWithBehavior:FBSDKLoginBehaviorBrowser];
}
}];
} else {
[self logInWithBehavior:FBSDKLoginBehaviorBrowser];
}
}];
break;
}
// intentional fall through.
}
case FBSDKLoginBehaviorBrowser: {
.
.
.
}
As we see in the code, we know if the app is installed in this if, if ([FBSDKInternalUtility isFacebookAppInstalled])
. 正如我们在代码中看到的,我们知道应用程序是否安装在if if,
if ([FBSDKInternalUtility isFacebookAppInstalled])
。 To solve the problem, I have changed this line 为了解决这个问题,我改变了这一行
BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];
to 至
BOOL useNativeDialog = YES;
I know this is not a good practice and it will change if I update this Pod, but at least is working and I needed it now. 我知道这不是一个好习惯,如果我更新这个Pod,它会改变,但至少是工作,我现在需要它。 I guess we can change that configuration in facebook developers admin site, but I haven't found anything.
我想我们可以在facebook开发者管理网站上更改该配置,但我还没有找到任何内容。
Facebook has changed Facebook login behavior for iOS9. Facebook改变了iOS9的Facebook登录行为。
Here is the quote from Facebook blog post : 以下是Facebook博客文章的引用:
We've been monitoring data and CTRs for over 250 apps over the last 6 weeks since iOS 9 launched.
自iOS 9推出以来,我们一直在监控超过250个应用的数据和点击率。 The click-through rate (CTR) of SVC Login outperforms the CTR of app-switch Login and is improving at 3x the rate of the app-switch experience.
SVC登录的点击率(CTR)优于app-switch登录的点击率,并且以app-switch体验的3倍速度提升。 This indicates that the SVC experience is better for people and developers today, and will likely be the best solution in the long run.
这表明SVC体验对于今天的人和开发人员来说更好,并且从长远来看可能是最好的解决方案。 For this reason, the latest Facebook SDK for iOS uses SVC as the default experience for Login.
因此,最新的iOS SDK SDK使用SVC作为Login的默认体验。
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 Attemps 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,
};
there is lot of behaviour available to access the fb login.try using alternate what you prefer from this. 有很多行为可以访问fb login.try使用备用你喜欢的东西。
FBSDKLoginManager *loginmanager = [[FBSDKLoginManager alloc] init];
loginmanager.loginBehavior=FBSDKLoginBehaviorNative;
Like this ...hope this will help you :) 喜欢这个...希望这会对你有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.