iOS 9 safari iframe src with custom url scheme not working

前端 未结 2 1743
难免孤独
难免孤独 2020-12-12 18:37

I use this solution https://gist.github.com/davidwkeith/2662899 to redirect from web page into my app if app installed. But it doesn\'t work on iOS 9. It\'s still working in

2条回答
  •  既然无缘
    2020-12-12 18:59

    Yes with iOS9 now you can deep link. Check the link for detailed explanation but I laid out the basics.

    http://blog.hokolinks.com/how-to-implement-apple-universal-links-on-ios-9/

    first you must go to your target and click capabilities. Add the associated domain.

    Next you must upload apple-app-site-association file.

    Basically open a JSON editor and construct something like this

    {
      "applinks": {
    "apps": [],
    "details": {
      "TBEJCS6FFP.com.domain.App": {
        "paths":[ "*" ]
      }
    }
      }
    }
    

    Next you must support Univeral links in your app. You need to implement

    extension AppDelegate {
    func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
        if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
            let webpageURL = userActivity.webpageURL! // Always exists
            if !handleUniversalLink(URL: webpageURL) {
                UIApplication.sharedApplication().openURL(webpageURL)
            }
        }
        return true
    }
    
    private func handleUniversalLink(URL url: NSURL) -> Bool {
        if let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: true), let host = components.host, let pathComponents = components.path?.pathComponents {
            switch host {
            case "domain.com":
                if pathComponents.count >= 4 {
                    switch (pathComponents[0], pathComponents[1], pathComponents[2], pathComponents[3]) {
                    case ("/", "path", "to", let something):
                        if validateSomething(something) {
                            presentSomethingViewController(something)
                            return true
                        }
                    default:
                        return false
                    }
    

提交回复
热议问题