2017-09-28 1 views
1

私たちのiOSアプリケーションでディープリンクを実装するためにBranchを使用しています。今私は、アプリケーションを実行し、ブランチでリンクを介してそれを開こうとすると、branch.initSessionが呼び出され、私は深いリンクのデータにアクセスすることができます。しかし、アプリケーションが起動していないときにブランチリンクを直接開こうとすると、branch.initSessionからのandRegisterDeepLinkHandlerコールバックが実行されません。これは基本的にディープリンクのポイントを無効にします。`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

。問題はapplication(_:,didFinishLaunchingWithOptions:)の戻り値AppDelegateです。私たちはfacebookで戻り値の生成をSDKApplicationDelegate.sharedに委任しています。 branch.initSessionapplication(_:,didFinishLaunchingWithOptions:)trueを返す必要があると思われますが、上記のケースではSDKApplicationDelegate.sharedがfalseを返しました。

これは文書化されていますが、特に、ブランチとfacebook 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とき統合のFacebookからの回答、以下の私が始まりました。私はanswerもそこに修正を加えて追加したので、他の人もそれに該当しないという機会があります。

これにより、数時間で節約できます。

+1

ありがとう、ミラノ。私は支店を使っているメインプロジェクトを調べていました。 – Glenn

関連する問題