Redirect to application if installed, otherwise to App Store

后端 未结 8 2530
渐次进展
渐次进展 2020-12-02 04:52

I know it\'s possible to link directly to an app in iOS by registering a custom scheme (e.g. so://) and it\'s also possible to link to the app in the appstore via itunes.

相关标签:
8条回答
  • 2020-12-02 05:06

    There are few simple steps to achieve this Action

    Step 1

    Go -> Project (select target) -> info -> URL Types

    Create URL Scheme in Xcode Like this

    here URL Scheme is myApp (it is better to have all character in lowercase).

    Step 2

    Setup Delegate if you have plan to receive parameters/Query strings from URL

    Here is the code :

    - (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
                options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    
         NSLog(@"APP : simple action %@",url.scheme);
    
        if ([url.scheme hasPrefix:@"myapp"]) {
    
            NSLog(@"APP inside simple %@",url.absoluteString);
    
    
            NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url
                                                        resolvingAgainstBaseURL:NO];
            NSArray *queryItems = urlComponents.queryItems;
            NSString * abc = [self valueForKey:@"abc"
                               fromQueryItems:queryItems];
            NSString * xyz = [self valueForKey:@"xyz"
                               fromQueryItems:queryItems];
    
    
            NSLog(@"Sid up = %@", abc);
    
            NSLog(@"PID up = %@", xyz);
    
          // you can do anything you want to do here
    
    
    
            return YES;
        }
    return NO;
    }
    

    End of Xcode side Work.

    Step 3

    Referring @BananaNeil Code here as i am not Front end guy

    (function() {
      var app = {
        launchApp: function() {
          window.location.replace("myApp://share?abc=12&xyz=123");
          this.timer = setTimeout(this.openWebApp, 1000);
        },
    
        openWebApp: function() {
          window.location.replace("http://itunesstorelink/");
        }
      };
    
      app.launchApp();
    })();
    

    Hope it will HELP you all

    0 讨论(0)
  • 2020-12-02 05:07

    There is no way to check for this. However, there is a nice workaround.

    The idea is basically this:

    1. The first time you open your app, you open up mobile safari from within your app to a predefined URL on your server
    2. On that URL you set up a cookie, like appInstalled to the users mobile safari
    3. You then kick the user back to your app with your registered scheme (same as FB does with SSO)
    4. All your email links point to your website, but on the website you check if the browser is mobile Safari and if the appInstalled cookie exists
    5. If either the browser is not mobile Safari or the cookie is not found, you redirect to the AppStore, or stay in your webpage.
    6. If the conditions of #4 are true, you redirect the user to your app with the registered scheme
    7. If the app has been deleted by the user, so the custom url scheme fails, you have a fail-safe redirect to the appstore

    The 2 last steps are explained on this SO post

    0 讨论(0)
  • 2020-12-02 05:10

    I think the more simple answer would be to set up a page on your server with the following javascript:

    (function() {
      var app = {
        launchApp: function() {
          window.location.replace("myapp://");
          this.timer = setTimeout(this.openWebApp, 1000);
        },
    
        openWebApp: function() {
          window.location.replace("http://itunesstorelink/");
        }
      };
    
      app.launchApp();
    })();
    

    This basically attempts to redirect to your app and sets a timeout to redirect to the app store if it fails.

    You could even make the code a little more smart, and check the user agent to see if they are an ios user, an android user, or a webuser, and then redirect them appropriately.

    0 讨论(0)
  • 2020-12-02 05:13

    "Smart App Banners" - not sure when they showed up but after finding this post looking for same, then Smart App Banners, this is follow up.

    Smart App Banners are a single line html meta tag in the header of each page you want to offer your app over the web experience :

    <meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
    

    which shows that icon at the top of the page and "Open this page in" with either the app or routing to the App Store.

    The metadata for this page on the iPhone looks like this (anonymized of course):

    <meta name="apple-itunes-app" content="app-id=605841731, app-argument=lync://confjoin?url=https://meet.rtc.yourcorporatedomain.com/firstName.lastName/conferenceID">
    

     Apple Developer Documentation - Promoting Apps with Smart App Banners

    0 讨论(0)
  • 2020-12-02 05:17

    Yeah its pretty easy. This requires the app you want to open to have a url scheme declared in the plist:

    //if you can open your app
    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"yourapp://"]])
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"yourapp://"]];
    }
    else
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ituneappstorelink"]];
    }
    
    0 讨论(0)
  • 2020-12-02 05:21

    There are a bunch of complicated edge cases here, so the easiest solution is to let someone else handle that stuff.

    This is what https://branch.io/ do. You can use their free plan to achieve exactly what you want, with a handful of bonus features

    • statistics
    • you can pass info along with the link, and it will be retrieved even if the user had to do an install first
    • link will work on the desktop (by default, it will text an install link to your mobile)

    I'm not affiliated with Branch.io, but I do use their product.

    0 讨论(0)
提交回复
热议问题