swift2 Universal Link在iOS 9的应用程序中无法打开

prdp8dxp  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(230)

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
}
  • 我提到的链接https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html#//apple_ref/doc/uid/TP40016308-CH12-SW2
  • 创建了名为apple-app-site-association的json文件
{ 
                "applinks":
                {
                                "apps":[],
                                "details":
                                {
                                                "teamId.com.test.testApp":
                                                {
                                                                "paths":["*"]
                                                }
                                }
                }
}
  • 我签署了apple-app-site-association文件,但因为我使用的是iOS9,所以不需要签署。
  • 我实现了方法application:continueActivity并返回YES。
  • 但我的链接没有在应用程序中打开,而是在Safari中打开。
xuo3flqw

xuo3flqw1#

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

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

您可以在以后使用Apple verification tool来验证这一点。
请注意,即使您使用的是iOS9,您仍然需要通过https提供apple-app-site-association文件。

相关问题