2016-09-28 95 views
0

對於我正在開發的應用程序,我添加了Facebook登錄SDK。我之前做過其他應用程序,但我遇到了一些意想不到的行爲。出於某種原因,安裝後第一次啓動應用程序時,按(自定義)Facebook登錄按鈕無法打開人們期望出現的Safari登錄屏幕。登錄事件的處理程序永遠不會被調用,從而阻止我甚至顯示錯誤。iOS Facebook自定義登錄在第一次安裝時沒有響應

以前有人遇到過這個嗎?

代碼: AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    [[FBSDKApplicationDelegate sharedInstance] application:application 
         didFinishLaunchingWithOptions:launchOptions]; 
    // Some other setup code 

    return YES; 
} 

- (BOOL) application:(UIApplication *)app 
     openURL:(NSURL *)url 
     options:(NSDictionary<NSString *,id> *)options 
{ 
    BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:app 
                   openURL:url 
                sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] 
                  annotation:options[UIApplicationOpenURLOptionsAnnotationKey] 
       ]; 
    handled |= [GIDSignIn.sharedInstance handleURL:url 
          sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] 
            annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]; 
    return handled; 

} 

- (BOOL)application:(UIApplication *)application 
     openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication 
    annotation:(id)annotation 
{ 
    BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application 
               openURL:url 
            sourceApplication:sourceApplication 
              annotation:annotation]; 
    handled |= [GIDSignIn.sharedInstance handleURL:url sourceApplication:sourceApplication annotation:annotation]; 
    return handled; 
} 

自定義Facebook的身份驗證:

-(void)authenticate: (UIViewController *) viewController onCompletion: (void (^)(NSMutableDictionary *bundle, NSError *error))completion { 
    successBundle = [BundleUtils generateBundle:YES]; 

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 
    [login logInWithReadPermissions: permissions 
     fromViewController:viewController 
     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
     // Never Reached 
    }]; 
} 

以及相關的info.plist部分(其中自變量爲每個生成配置的用戶自定義變量聲明使用)

<plist version="1.0"> 
<dict> 
    <key>CFBundleURLTypes</key> 
    <array> 
     <dict> 
      <key>CFBundleURLSchemes</key> 
      <array> 
       <string>fb${FacebookAppId}</string> 
      </array> 
     </dict> 
    </array> 
    <key>FacebookAppID</key> 
    <string>${FacebookAppId}</string> 
    <key>FacebookDisplayName</key> 
    <string>${FacebookAppName}</string> 
    <key>LSApplicationQueriesSchemes</key> 
    <array> 
     <string>fbapi</string> 
     <string>fb-messenger-api</string> 
     <string>fbauth2</string> 
     <string>fbshareextension</string> 
    </array> 
</dict> 
</plist> 

任何人都看到我是什麼失蹤?

回答

0

我發現了這個問題。由於我在身份驗證功能中實例化了FBLoginManager,因此它將被釋放,而loginWithPermissions仍在處理中。但是,這導致登錄管理器的引用不再具有適當的值。

將​​移動到initalizer並跨會話存儲登錄修復我的問題。事實上,這隻發生在第一次設置上可能與花費更長的時間完成相關,增加了登錄被釋放的機會。

相關問題