Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mikkel.S 33 posts 167 karma points
    Feb 02, 2023 @ 12:41
    Mikkel.S
    0

    apple-app-site-association (deeplinking) and Umbraco 10

    Hey guys!

    I am trying to enable some deeplinking from my site and I have been unable to find out how it works for IOS. Android works out of the box but IOS will not accept my current setup. I have Googled a bit and this is my current configuration:

    I have added "UmbracoReservedPaths": "~/.well-known/,~/apple-app-site-association" to my AppSettings.Json file to enable access to the URL. But accessing the url domain.com/.well-known/apple-app-site-association only returns a classic 404.

    Then I tried adding the following to my startup.cs file: app.UseRewriter(new RewriteOptions().AddIISUrlRewrite(env.ContentRootFileProvider, "IISUrlRewrite.xml")); which I assumed created a link between my application and a custom config file that has some specific rewrite rules:

       <?xml version="1.0" encoding="utf-8" ?>
    <rewrite>
        <rules>
            <rule name="apple_json_file">
                <match url="^apple-app-site-association" />
                <action type="Rewrite" url="apple-app-site-association.json" />
            </rule>
        </rules>
    </rewrite>
    

    Neither of these approaches have helped. I read somewhere that the file needed a JSON extension, but enabling that only enables the ability to actually hit the URL and see the JSON, but IOS still does not work as intended.

    Have you guys tried deeplinking from an Umbraco 9, 10 or 11 site yet? If so, what am I missing here? :-)

    Thanks!

  • Roy Berris 89 posts 576 karma points c-trib
    Feb 02, 2023 @ 15:57
    Roy Berris
    0

    I don't think this is related to the umbraco set-up but to the iOS app that should respond to a deeplink. iOS has some strict rules on deeplinking. I am not a iOS dev, but if I was in this scenario I would look at permissions etc on the iOS side.

  • Mikkel.S 33 posts 167 karma points
    Feb 06, 2023 @ 06:45
    Mikkel.S
    1

    Hey Roy,

    Thanks for replying!

    I will try and figure out how IOS expects a deeplink "app-site-association" file to look like and how it should be handled in an app or elsewhere.

    Thanks!

    FYI. If I find out that the IOS app or service is the issue, I will mark your answer as the solution and post what had to be done in the app to make it work :-)

  • Daniel 13 posts 103 karma points
    Aug 03, 2023 @ 08:29
    Daniel
    0

    It seems like some specific routes are handled differently by Umbraco. The address /.well-known/apple-app-site-association was not handled by the IContentLastChanceFinder either, but as you wrote only returned a generic 404.

    However it is possible to add a custom middleware to handle this situation.

    Adding this to the startupFile:

        services.AddSingleton<AppleAssociationMiddleware>();
        /// 
        app.UseMiddleware<AppleAssociationMiddleware>();
    

    And then having a middleware like this solved it for me:

    public class AppleAssociationMiddleware : IMiddleware
    {
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            if (context.Request.Path == "/.well-known/apple-app-site-association")
            {
                context.Response.StatusCode = StatusCodes.Status200OK;
                context.Response.ContentType = "application/json";
                string baseDirectory = AppContext.BaseDirectory;
                string filePath = Path.Combine(baseDirectory, "apple-app-site-association");
    
                string fileContents = System.IO.File.ReadAllText(filePath);
                await context.Response.WriteAsync(fileContents);
                return;
            }
            await next(context);
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft