0

我讀過http://developers.facebook.com/docs/howtos/link-to-your-native-app/,我很困惑我如何在3.0中處理深度鏈接。假設用戶點擊了我的應用程序的appRequest,FB用特殊的URL打開我的應用程序。我有我的appDelegate的OpenURL方法做:Facebook中的深度鏈接和FBSessionDelegate iOS SDK 3.0

return [FBSession.activeSession handleOpenURL:url]; 

的教程說:

If your app requires an authorized user, handle the processing of the target URL in the 
SDK callbacks implemented after a successful login, the fbDidLogin method. 

然而,fbDidLogin委託方法不再是因爲在3.0叫我們切換到使用FBSession.activeSession而不是使用facebook.m對象。事實上,沒有任何FBSessionDelegate方法會被調用,因爲facebook對象的狀態從不改變。那麼我應該在哪裏處理URL?

回答

0

您可能會在打開會話時設置的處理程序中處理此問題。

說,例如,你使用類似會議開幕:

[FBSession openActiveSessionWithReadPermissions:nil 
             allowLoginUI:YES 
           completionHandler:^(FBSession *session, 
                FBSessionState state, 
                NSError *error) { 
            [self sessionStateChanged:session 
                 state:state 
                 error:error]; 
           }]; 

你可以把把深層鏈接處理中設置來處理,你可以定義會話更改方法的代碼,例如:

- (void)sessionStateChanged:(FBSession *)session 
         state:(FBSessionState) state 
         error:(NSError *)error 
{ 
    switch (state) { 
     case FBSessionStateOpen: 
      if (!error) { 
       // Handle deep link  
      } 
      break; 
     case FBSessionStateClosed: 
      self.user = nil; 
      break; 
     case FBSessionStateClosedLoginFailed: 
      self.user = nil; 
      [FBSession.activeSession closeAndClearTokenInformation]; 
      break; 
     default: 
      break; 
    } 

    if (error) { 
     UIAlertView *alertView = [[UIAlertView alloc] 
            initWithTitle:@"Error" 
            message:error.localizedDescription 
            delegate:nil 
            cancelButtonTitle:@"OK" 
            otherButtonTitles:nil]; 
     [alertView show]; 
    } 
} 

要查看深度鏈接處理的工作示例,請參閱https://github.com/fbsamples/ios-social-cafe/