简体   繁体   中英

Facebook authorize dialog in app not in safari

I want the user to login with his facebook inside my app, but I don't want that the app goes to Safari and then get back to the app.

I found some people answer this by calling this method [self authorizeWithFBAppAuth:NO safariAuth:NO]; in facebook.m

My problem is that I don't have a facebook.m file and I don't have this function implemented.

I'm using the latest facebook SDK 3.1 How can I solve this please?.

thanks

Here is what I am doing to make login open in dialog box. But it has double of disadvantages, because if the user has account in Settings, then the login will not ask him to access his account. This method will always use the WebView (login dialog) login.

FBSession *session = [[FBSession alloc] initWithAppID:@"283938491920393" // here use your app id
                                          permissions:@[@"read_stream"] // you can change this parameter
                                      defaultAudience:FBSessionDefaultAudienceFriends 
                                      urlSchemeSuffix:@"fb"
                                   tokenCacheStrategy:nil];
        // Set the active session
[FBSession setActiveSession:session];

    // Open the session
[session openWithBehavior:FBSessionLoginBehaviorForcingWebView
                completionHandler:^(FBSession *session,
                                    FBSessionState status,
                                    NSError *error) {
                    // Respond to session state changes,
                    // ex: updating the view
                    if(!error && session.isOpen)
                    {
                        // user has logged in
                    }
                    else
                    {
                        if(error)
                        {
                           // error
                        }
                        else
                        {
                            // handle the session state change
                            [self session:session
                          hasChangedState:status
                                withError:error];
                        }
                    }
                }];

Have you looked at this method?

- (void)openWithBehavior:(FBSessionLoginBehavior)behavior
   completionHandler:(FBSessionStateHandler)handler;

These are the behaviors available:

typedef enum {
/*! Attempt Facebook Login, ask user for credentials if necessary */
FBSessionLoginBehaviorWithFallbackToWebView      = 0,
/*! Attempt Facebook Login, no direct request for credentials will be made */
FBSessionLoginBehaviorWithNoFallbackToWebView    = 1,
/*! Only attempt WebView Login; ask user for credentials */
FBSessionLoginBehaviorForcingWebView             = 2,
/*! Attempt Facebook Login, prefering system account and falling back to fast app switch         if necessary */
FBSessionLoginBehaviorUseSystemAccountIfPresent  = 3,
} FBSessionLoginBehavior;

You can also just manage the entire web / authentication outside the API and then set the active session token after you've authenticated.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM