我正在运行使用Facebook SDK( 4.9.1 )的问题,如果没有系统帐户,则会在应用浏览器中打开以进行登录。
从系统登录Facebook帐户效果很好。我使用以下代码
FBSDKLoginManager *manager = [[FBSDKLoginManager alloc] init];
manager.loginBehavior = FBSDKLoginBehaviorSystemAccount;
[manager logInWithReadPermissions:@[@"public_profile",@"email",@"user_friends"] fromViewController:controller handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
success(kFacebookStatusFailed);
} else if (result.isCancelled) {
success(kFacebookStatusCancelled);
} else {
success(kFacebookStatusSuccess);
}
}];
我已正确完成所有必需的info.plist设置[{3}}。
问题是当它使用inapp浏览器登录时,实际使用调试找到的 SafariViewController 。它经历了所有登录过程,但最后它陷入了一个白色的空白屏幕并且没有被忽视,请参见下面的截图
已尝试过所有可能的步骤,但无法克服它。但是当我设置新项目时,只有上面的登录代码和正确的设置,一切正常。
Fresh Project和Original Project的唯一区别是应用程序中使用的不同框架的数量,例如 Crashlytics , Fabric , Instabug ,谷歌框架等。有什么理由我应该怀疑这些框架导致问题,我想不。那么,可能是什么问题,任何遇到同样问题并能帮助我的人都会非常感激。
谢谢。
答案 0 :(得分:6)
我遇到了同样的问题。将其添加到AppDelegate:
在AppDelegate.m中
在application:didFinishLaunchingWithOptions:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
将以下方法添加到AppDelegate.m:
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}
我不知道SafariViewController
是否会检查application:openURL:sourceApplication:annotation
但这对我有用。
试试看。我希望它适合你。
答案 1 :(得分:2)
是登录时出现问题。您可以尝试这样
-(IBAction)fbAction:(id)sender
{
FBSDKLoginManager *manager = [[FBSDKLoginManager alloc] init];
manager.loginBehavior=FBSDKLoginBehaviorWeb;
if ([FBSDKAccessToken currentAccessToken])
{
[manager logOut];
NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
[self fetchUserInfo];
}
else
{
[manager logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
NSLog(@"Login process error");
}
else if (result.isCancelled)
{
NSLog(@"User cancelled login");
}
else
{
NSLog(@"Login Success");
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"result is:%@",result);
[self fetchUserInfo];
}
}
}];
}
}
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, email"}]
//[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, first_name, last_name, picture.type(large), email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(@"results:%@",result);
NSString *email = [result objectForKey:@"email"];
NSString *userId = [result objectForKey:@"id"];
if (email.length >0 )
{
NSLog(@"email %@,userid %@",email,userId);
}
else
{
NSLog(@"Facebook email is not verified");
}
}
else
{
NSLog(@"Error %@",error);
}
}];
}
}
答案 2 :(得分:0)
对我来说,我安装了print("Manhattan distance: ",sum(abs(x-y) for x,y in zip(UserXRatings, UserYRatings)))
#It should print - Manhattan distance: 22.5
SDK并且我的Branch
app委托方法搞砸了。
openURL:
只打开- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary <NSString *, id> *)options
个链接,而
Branch
正在打开- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
和Facebook
个链接。
仔细检查两种方法(iOS9和&lt; = iOS8)中的逻辑是否设置正确。
答案 3 :(得分:0)
抱歉,我不会“说”目标C,但你必须覆盖OpenUrl。 这是C#:
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
// Facebook - We need to handle URLs by passing them to their own OpenUrl in order to make the SSO authentication works.
return ApplicationDelegate.SharedInstance.OpenUrl(application, url, sourceApplication, annotation);
}