Universal Links iOS

ⅰ亾dé卋堺 提交于 2020-01-06 21:03:48

问题


I am having some trouble in getting Universal links on my app working. Here are the things that i have already done.

-- Created my apple-app-site-association file. Here is my file

{

    "applinks": {
                "apps": [],
                "details": [{
                    "appID": "XXXXXXXXXX.com.companyName.app",
                    "paths": ["/view/*", "/class/*"]
                }]
            }
}

I have not signed my file and i set my project deployment target to iOS 9.2 (so that i don't have to sign this file).

-- Added the associated domain in my project capabilities

applinks:companyName.com
applinks:www.companyName.com

-- Associated domains are also enabled in my developer portal

-- Updated the provisioning profiles and used the new ones

-- Added the entitlement to the build.

-- Overrided this delegate method

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler

The file is available from my HTTPS server and i checked the universal links status from this apple validator. https://search.developer.apple.com/appsearch-validation-tool/ The validator is validating this. But when i click on the link which is in iMessage and the link is like companyName.com/view/7375, then it will open in safari and my app does not get any call back.

Any idea what i am missing


回答1:


It may be that the OS now considers handling your URL in "override" mode -- why it goes into Safari.

When your app resolves a Universal Link, in the upper-right corner of the screen you'll see someting like "companyName.com -->". If you tap that, that's the OS's way of "overriding" how the Universal Link is handled, and opens it in Safari at that time and forevermore.

Try going back into the Messages app and long press on your link. After a second or two, you should see an action sheet come up that gives you options like "Open in Safari" and "Open in 'Your App Name'". Select the "open in your name" option. That should then "reset" how the OS views handling your Universal Links, now directing them back into your app.




回答2:


You also have to implement the following AppDelegate function.

- (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType

I had the same issue. Unfortunately this is not well documented by Apple.




回答3:


When you support universal links, iOS 9 users can tap a link to your website and get seamlessly redirected to your installed app without going through Safari. If your app isn’t installed, tapping a link to your website opens your website in Safari.

Here, how to setup your own server, and handle the corresponding links in your app.

Go Apple developer page

Register your app at developer.apple.com. Enable ‘Associated Domains’ on your app identifier.

Enable ‘Associated Domain’ on in your Xcode project The error “Add the associated Domains feature to your App ID” will go away once you enable the Associated Domains in your APP ID in developer.apple.com as in the previous step. If it doesn’t go away, quit and relaunch the xcode few times and it will work.

Add the proper domain entitlement and make sure the entitlements file is included at build: Xcode will do it automatically by itself.

Then create apple-app-site-association file using Terminal

Use this commands for creating AASA(apple-app-site-association) File.

  1. cd desktop

  2. touch apple-app-site-association

Then open AASP FILE and write this json format data

{
"applinks": {
    "apps": [ ],
    "details": [

        {
            "appID": "TeamID.BundleID2",
            "paths": [ "*" ]
        }
    ]
}
}

Once you are ready with your AASA file, you can now host https://<>/.well-known/apple-app-site-association
Upload the apple-app-site-association file to your HTTPS web server. You can place the file at the root of your server or in the .well-known subdirectory.

APPLE APP SITE ASSOCIATION (AASA) VALIDATOR Goto the following link and enter your domain name. It will check if AASA file is valid and is accessible . Link: https://branch.io/resources/aasa-validator/#resultsbox

Once done then add this below code in your Appdelgate

Swift4

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    print("Continue User Activity called: ")
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        let url = userActivity.webpageURL!
        print(url.absoluteString)
        //handle url and open whatever page you want to open.
    }
    return true
}

Objective-c

-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler{
    if ([userActivity.activityType isEqualToString: NSUserActivityTypeBrowsingWeb]) {
        NSURL *url = userActivity.webpageURL;

        }

    return YES;
}

Then check your entitlement add to the app target and run it will redirect to your app.Make sure the AASA File will validate like below screen then its redirect to your application.If anything miss it was not redirect to your app.

Inside your server any content type validation error came then you can create one .htaccess file and inside that u can write this code .

<Files "apple-app-site-association">
ForceType 'application/json'
</Files>

This procedure worked from my side .I hope your side also working properly. If you enjoyed reading this post .



来源:https://stackoverflow.com/questions/36177732/universal-links-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!