iOS: Connect to Facebook without leaving the app for authorization

后端 未结 2 2139
栀梦
栀梦 2020-12-08 12:19

I know that it was possible before the Graph API.

I work on an iPhone app that may not be in the background (one of the requirements).
In addition there is a log

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 13:15

    Here you have an alternative solution.

    If you don't like to change the facebook sdk code and want a solution that allows you to choose between SSO or the old-fashioned mechanism, you can Implement an extension like this:

    //Facebook_SSOExtension.h
    --------------------------------------------------------
    
    @interface Facebook(SSOExtension)
    -(void) authorize:(NSArray*)permissions useSSO:(BOOL) useSSO;
    @end
    
    //Facebook_SSOExtension.m
    --------------------------------------------------------
    
    //So warnings do not appear
    @interface Facebook(PrivateSSOExtension)
    - (void)authorizeWithFBAppAuth:(BOOL)tryFBAppAuth
                        safariAuth:(BOOL)trySafariAuth;
    -(void) setPermissions:(NSArray*) permissions;
    @end 
    
    @implementation Facebook(SSOExtension)
    -(void) authorize:(NSArray*)permissions useSSO:(BOOL) useSSO
    {
        [self setPermissions: permissions];
        [self authorizeWithFBAppAuth:useSSO safariAuth:useSSO];
    }
    @end
    

    Even though this requires more work than commenting-out the sso code, you will be able to update the facebook-sdk without major problems (if they rename authorizeWithFBAppAuth:safariAuth: your extension will not work, use asserts to detect this issue quickly). Also, if you are building a reusable component to interact with facebook without repeating things over and over again, this will save you some work too.

    Cheers.

提交回复
热议问题