I am running with an issue with using Facebook SDK( 4.9.1 ) which opens in app browser for login if no system account present.
Login from system Facebook account works well. I am using the following code
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);
}
}];
I have correctly done all required info.plist settings defined here .
The problem is when it logs in using inapp browser, actually using SafariViewController found by debugging. It goes through all login process but in the end it stucks in a white blank screen and doesn't dismiss, see screenshot below
Have tried all possible steps but not able to get over it. But when I setup fresh project having nothing just the above login code and proper settings, all worked fine.
The only difference in the Fresh Project and Original Project is number of different frameworks used in the app, like Crashlytics , Fabric , Instabug , Google Frameworks etc. Is there any reason that I should suspect these framework that is causing problem, I think NO. So, what could be the problem, anyone who faced the same problem and can help me will be greatly appreciated.
Thank You.
I was having the same problem. Add this to your AppDelegate:
In AppDelegate.m
In application:didFinishLaunchingWithOptions:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; }
Add the following method to your 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]; }
I don't know if the SafariViewController
checks for the application:openURL:sourceApplication:annotation
but this worked for me. Give it a try. I hope it works for you.
Source: https://developers.facebook.com/docs/ios/getting-started
Yes There is a problem with Login .You Can try like this
-(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);
}
}];
}
}
For me, I had the Branch
SDK installed and my openURL:
app delegate methods were messed up.
- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary <NSString *, id> *)options
was only opening Branch
links, while
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
was opening both Facebook
and Branch
links.
Double check that the logic in both methods (iOS9 and <=iOS8) are setup correctly.
Sorry I don't "speak" objective C but you have to override OpenUrl. Here is 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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.