2016-12-14 9 views
2

Branch.ioリンクは、アプリが既にインストールされているとデータを取得できません。アプリインストールリンクがアプリを直接開くが、データが欠落している。しかし、もし私がアプリケーションの店にリダイレクトし、再度ブランチリンクをクリックし、直接アプリケーションを開くとデータが来る。以下のコードをご案内してください。Branch.io - アプリケーションを開くがデータを取得しないでください

更新:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
{ 
    let branch: Branch = Branch.getInstance() 
    branch.setDebug() 
    branch.initSessionWithLaunchOptions(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 
      print("params: %@", params.description) 
      print(params["event_id"]) 
      if let url = params["event_id"] as? NSInteger { 
       let strEventID = String(url) 
       print(strEventID) 


    }) 
    self.window?.rootViewController = nav 
    self.window?.makeKeyAndVisible() 
    return true 
} 

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { 

    Branch.getInstance().handleDeepLink(url) 

    if(sourceApplication == "com.linkedin.LinkedIn") 
    { 
     if(LISDKCallbackHandler.shouldHandleUrl(url)) 
     { 
      return LISDKCallbackHandler.application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
     } 
    } 

    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
} 

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool { 
    // handler for Universal Links 
    Branch.getInstance().continueUserActivity(userActivity) 
    return true 
} 

// Called when a notification is received and the app is in the 
// foreground (or if the app was in the background and the user clicks on the notification). 
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) 
{ 
    Branch.getInstance().handlePushNotification(userInfo) 
    if(UserSingleton.sharedInstance.accessToken != kEmptyString) 
    { 
     if let aps = userInfo["aps"] as? NSDictionary { 

      var title = kEmptyString 
      var message = kEmptyString 
      var inviteID = kEmptyString 
      var statusType = kEmptyString 

      if let inviteIDLocal = aps.valueForKey("id") as? NSNumber 
      { 
       inviteID = "\(inviteIDLocal)" 
      } 

      else if let inviteIDLocal = aps.valueForKey("id") as? String 
      { 
       inviteID = inviteIDLocal 
      } 
      else 
      { 
       inviteID = "0" 
      } 

      if let statusTypeLocal = aps.valueForKey("status_type") as? String 
      { 
       statusType = statusTypeLocal 
      } 

      if let titleLocal = aps.valueForKey("alert")?.valueForKey("title") as? String 
      { 
       title = titleLocal 
      } 

      if let messageLocal = aps.valueForKey("alert")?.valueForKey("body") as? String 
      { 
       message = messageLocal 
      } 
      CommonFunctions.addNotificationBar(title,message: message, inviteID: inviteID,statusType: statusType) 
     } 
    } 
} 
+0

これはあなたの 'continueUserActivity'実装の問題のようです。 AppDelegateファイルから 'didFinishLaunching'メソッド全体を投稿してください。 –

+0

sure @AlexBauer質問が更新されたことを確認してください –

答えて

-2

日過ごした後、最終的にはその理由を知るようになりました。 branch.io linkからの悪い仕事。彼らのコードのバグ。

// Respond to Universal Links 
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([**Any**]?) -> Void) -> Bool { 
// pass the url to the handle deep link call 
Branch.getInstance().continue(userActivity) 

return true 
} 

"Any"は実際には "AnyObject"である必要があります。

+0

これは実際には*正しくありません。 AppleのこのメソッドのAPIリファレンス(https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623072-application)に見られるように、ブランチのドキュメントはSwift 3については正確です。しかし、このメソッドで 'AnyObject'を使用すると、Swift 2.3では正しくなりました。構文の相違の詳細[ここ](http://stackoverflow.com/questions/40673319/ios-swift-2-3-correct-syntax-for-application-restorationhandler)。申し訳ありませんが問題に遭遇しました! –

+0

@AlexBauer速報2に取り組んでいる私のような人が速攻3を開始していない人は困ってしまうので、そして、ここでも私は何のエラーもないので、間違っています。ドキュメントでは、そのようなことを指定する必要があります。明確化のために、あなたはもっと良く知っています。 –

+0

@AlexBauerあなたが私を案内してくれますか、リンクはアプリケーションを開いてデータを取得していませんが、アプリケーションを終了してリンクから開始するとデータを渡さず、アプリケーションが正常に再起動したとき(リンクからではありません) –

関連する問題