2016-12-29 84 views
0

請幫我解決這個問題。我已經通過以下https://www.raywenderlich.com/128948/universal-links-make-connection實現了通用鏈接,並且我得到的問題是當我單擊鏈接時,我被重定向到Web瀏覽器而不是應用程序。在Safari瀏覽器中,當我向下滾動頁面時,我也會看到一個帶有OPEN按鈕的橫幅。通過點擊它,我的應用程序打開並根據邏輯打開特定的視圖控制器。那麼爲什麼它最初是在瀏覽器中打開?如果安裝了應用程序,則應直接在應用程序中打開而不是在網絡瀏Universal Links在Safari瀏覽器上顯示橫幅

以下是我的應用程序委託方法:

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool { 

     if userActivity.activityType == NSUserActivityTypeBrowsingWeb { 
      guard let url = userActivity.webpageURL else { 
       return false 
      } 
      openViewController(url) 
     } 
     return true 
    } 

func openViewController(url: NSURL) { 
     let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: true) 
     print(components) 
     print(url.absoluteString) 
     if url.host == "refit.co" && (url.pathComponents![2] == "supplements" || url.pathComponents![2] == "equipments") { 
      print("This is the supplements/equipments universal link") 
      let storyboard = UIStoryboard(name: "Main", bundle: nil) 
      let vc = storyboard.instantiateViewControllerWithIdentifier("Home") 
      let navController = self.window?.rootViewController as? UINavigationController 
      navController?.pushViewController(vc, animated: false) 
      let vc2 = storyboard.instantiateViewControllerWithIdentifier("SupplementDetail") as? VCSupplementDetail 
      vc2?.itemID = getID(url.query!) 
      vc2?.screenName = url.pathComponents![2] == "supplements" ? "Supplements" : "Equipments" 
      navController?.pushViewController(vc2!, animated: true) 
      print("Query: \(url.query)") 
     } else { 
      print("This is the url: \(url)") 
      print(url.host) 
      print(url.path) 
      print(url.query) 
      print(url.pathComponents) 
     } 
    } 

回答

0

這聽起來像你無意中停用通用鏈接。如果您在打開通用鏈接後點擊屏幕右上角的旁路鏈接,通常會發生這種情況。有關如何撤銷流程的詳細信息,請參見this answer

+0

謝謝@AlexBauer。所以這是Universal Links的限制 –

+0

Yessir,不幸的是:( –