Universal Link未在iOS 9的应用程序中打开

时间:2016-01-05 05:44:23

标签: ios swift2 ios-universal-links

info.plist文件中创建了URL类型,其URL方案为http。创建了NSUserActivity类型。在'ViewController'类中创建了权限UIWebView。我在AppDelegate方法中实现了以下代码:

func application (application: UIApplication,willContinueUserActivityWithType userActivityType: String) -> Bool  {
    let sharedUserActivityType = "com.test.testApp"
    if (userActivityType == sharedUserActivityType) {
        return true
    }
    return false
}

@available(iOS 8.0, *)

internal override func restoreUserActivityState(activity: NSUserActivity) {

    //don't forget to call super!

    if #available(iOS 8.0, *) {

        super.restoreUserActivityState(activity)

        let userInfo = activity.userInfo

    } else {
            // Fallback on earlier versions

    }
}

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

    if  userActivity == "com.test.testApp.view"
    {
        let mainListing = ViewController()

        restorationHandler([mainListing])
    }

    if let window = self.window 
    {
        window.rootViewController?.restoreUserActivityState(userActivity)
    }

    return true
}

func application(app: UIApplication, openURL url: NSURL, options: 
        [String : AnyObject]) -> Bool {

    return true
}

1 个答案:

答案 0 :(得分:0)

您的apple-app-site-association JSON文件格式不正确 - 详细信息词典中缺少appID密钥,即

{ 
  "applinks": 
   { "apps":[], 
     "details": [
       {
         "appID": "teamId.com.test.testApp",  
         "paths":["*"] 
      } 
     ]
    } 
}

您可以在将来使用Apple verification tool进行验证。

即使您使用的是iOS9,也需要注意,您仍然需要通过https提供apple-app-site-association文件。