Reputation: 978
I'm following these instructions. The app is a Xamarin.Forms iOS app.
https://xamarinhelp.com/ios-universal-links/
Here's what I'm not sure about.
First, I add a well-known folder to my MVC 5 Web App. I could not add a .well-known folder. Since I could not add the "." in front of the folder, I added a virtual directory using the Azure Portal.
When I try to access the file using https://portal.mydomain.com/.well-known/apple-app-site-association, I get the following message.
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Second, I had to edit the Entitlements.plist using the XML text editor. Here is what my entry looks like.
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks: portal.mydomain.com</string>
<!--<string>your domain</string>-->
</array>
</dict>
</plist>
Next, here's what ContinueUserActivity and OpenUrl looks like.
//AppLinks app running
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { try { if (userActivity.ActivityType == "NSUserActivityTypeBrowsingWeb") { if (userActivity.WebPageUrl.AbsoluteString.Contains("/PublicOffers/OffersPage")) { ((App)Xamarin.Forms.Application.Current).AppLinkRequest(new Uri(userActivity.WebPageUrl.AbsoluteString)); return true; } } } catch { // Ignore issue for now } return base.ContinueUserActivity(application, userActivity, completionHandler); }
//AppLinks app not running
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) { try { var components = new NSUrlComponents(url, true); var path = components.Path; var query = components.Query; // Is this a known format? if (path == "/PublicOffers/OffersPage") { // Send to App.xaml.cs ((App)Xamarin.Forms.Application.Current).AppLinkRequest(new Uri(url.AbsoluteString)); return true; } } catch { // Ignore issue for now } //return false; return base.OpenUrl(app, url, options); }
Finally, I created this method that calls OnAppLinkRequestReceived.
public async void AppLinkRequest(Uri uri) { OnAppLinkRequestReceived(uri); }
The problem is that ContinueUserActivity and OpenUrl never get called.
Here is an example of the Url I want to open/prompt the app using Universal Links.
https://portal.mydomain.com/PublicOffers/OffersPage?id=SOMEGUID&cid=SOMEGUID
Any ideas, help or suggestions are greatly appreciated. Thanks!
UPDATE 1
I added a new web.config file to my well-known folder and configured it like so. I can now access both files. My iOS Universal Links are still not working, though.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="application/octet-stream" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
UPDATE 2
I finally realized why my Entitlements.plist file didn't contain an option for Associated Domains. In order to see that option, you have to right click on the file, select "Open With..." and choose "Property List Editor".
https://learn.microsoft.com/en-us/xamarin/ios/deploy-test/provisioning/entitlements?tabs=vswin
UPDATE 3
I just ran this validator tool and everything was green. It looks for the apple-app-site-association file.
http://branch.io/resources/aasa-validator/
Your domain is valid (valid DNS). Your file is served over HTTPS. Your server does not return error status codes greater than 400. Your file's 'content-type' header was found :) Your JSON is validated.
UPDATE 4
I just did a clean, rebuild and build. Universal Links are still not working.
UPDATE 5
I upgraded to Visual Studio 2017 Enterprise and Xamarin.iOS 11.9.1.24. I'm now using the 11.3 SDK and I still can't get Universal Links to work. I upgraded to Xamarin.Forms 2.5.1.444934 as well.
Upvotes: 6
Views: 4827
Reputation: 978
I finally got it to work by removing the space from this line.
<string>applinks: portal.mydomain.com</string>
It now reads like this.
<string>applinks:portal.mydomain.com</string>.
I figured it out because I was getting an error on submitting the app to the app store. The error was:
your application bundle's signature contains code signing entitlements that are not supported on iOS. Specifically, value applinks: portal.mydomain.com for key com.apple.developer.associated-domains in Payload...
Upvotes: 5
Reputation: 183
I had the same issues, apple-app-site-association file validated just fine and I implemented the ContinueUserActivity and OpenUrl-methods in AppDelegate.cs but my universal links were not working when building and deploying from my Windows machine using an external Mac build host.
So I figured that I should try the same procedure but this time running everything locally on my Mac build host with Visual Studio for Mac. Cloned the project, deleted the app from my phone, re-built the project, deployed and voilá, it worked like a charm.
Upvotes: 1