2017-09-28 1 views
1

우리는 iOS 앱에서 딥 링크를 구현하기 위해 Branch를 사용하고 있습니다. 이제 응용 프로그램을 실행 한 다음 지점 별 링크를 통해 열려고하면 branch.initSession이 호출되고 딥 링크 데이터에 액세스 할 수 있습니다. 그러나 앱이 실행되지 않을 때 지점 링크를 직접 열려고 시도하면 branch.initSessionandRegisterDeepLinkHandler 콜백이 실행되지 않습니다. 기본적으로 딥 링크의 핵심은 무효화됩니다.`Branch.initSession`은 앱이 링크에서 시작될 때`andRegisterDeepLinkHandler` 콜백을 호출하지 않습니다.

우리 AppDelegate 코드 : 우리는이 다음과 같은 방법으로 해결할 수있었습니다

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    let branch: Branch = Branch.getInstance() 
    branch.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: {params, error in 

     DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { 

      let alert = UIAlertController(title: "Branch", message: "\(params as? [String: AnyObject])", preferredStyle: .alert) 
      alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) 
      self.window?.rootViewController?.present(alert, animated: false, completion: nil) 
     }) 

     if error == nil { 
      // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app 
      // params will be empty if no data found 
      // TODO: ... insert custom logic here ... 
      print("params: %@", params as? [String: AnyObject] ?? {}) 
     } 
    }) 
    ... 
    // facebook SDK login integration 
    return SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions) 
} 

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { 
    // pass the url to the handle deep link call 
    let branchHandled = Branch.getInstance().application(application, 
                 open: url, 
                 sourceApplication: sourceApplication, 
                 annotation: annotation) 
    return branchHandled 
} 

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 
    // pass the url to the handle deep link call 
    let branchHandled = Branch.getInstance().application(app, 
                 open: url, 
                 options: options) 
    return branchHandled 
} 

답변

3

. 문제는 우리의 AppDelegateapplication(_:,didFinishLaunchingWithOptions:)의 반환 값입니다. 우리는 페이스 북으로 반환 값의 생성을 SDKApplicationDelegate.shared에 위임하고 있습니다. branch.initSessionapplication(_:,didFinishLaunchingWithOptions:)true을 반환해야하고 해당 문제의 경우 SDKApplicationDelegate.shared은 false를 반환해야합니다.

이것은 문서화되어 있지만, 특히 브랜치와 페이스 북 SDK를 함께 사용하여 문제가 발생한다는 사실을 모르는 경우에는 문서에서 다루기가 매우 어렵습니다.

documentation screenshot

따라서 수정은 application(_:,didFinishLaunchingWithOptions:) 구현을 갱신이었다 :

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    let branch: Branch = Branch.getInstance() 
    branch.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: {params, error in 
     if error == nil { 
     // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app 
     // params will be empty if no data found 
     // TODO: ... insert custom logic here ... 
     print("params: %@", params as? [String: AnyObject] ?? {}) 
     } 
     }) 
    ... 

    // facebook SDK login integration 
    SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions) 

    // always return true! 
    return true 
} 

그것은 모두가 날 때 통합 페이스 북 this question에서 답을 다음으로 시작되었다. 나는 answer에 수정 사항을 추가 했으므로 다른 버전도 해당 버전에 적합하지 않을 수 있습니다.

이렇게하면 몇 시간을 절약 할 수 있기를 바랍니다.

+1

감사합니다. 밀라노. 브랜치를 사용하는 내 프로젝트를 조사하고 있었는데 알아 냈습니다. – Glenn

관련 문제