Shared link that will open my app or the app store

二次信任 提交于 2020-01-07 03:27:09

问题


I have started working on an iPhone app and I decided I want the user to be able to share things from it on the web (through email, Facebook, twitter, messages and so on...). Now I want the link to the app (on the user's shared post) to be able to check whether my app is installed on the device and open it through it's URL scheme and in case it's not - Open a different link that leads to the app on the App Store.

I have done some research and understood that I should make a php on my server side or something along these lines, how ever I couldn't find a tutorial or a clear example for dummies (i know nothing about php/jscript/jquery)... could someone please give me a hand here?


回答1:


- (IBAction)openOtherAppButtonAction
{
    UIApplication *ourApplication = [UIApplication sharedApplication];
    NSString *URLEncodedText = [@"AppName" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *ourPath = [@"openapp://" stringByAppendingString:URLEncodedText];   //openapp is the url custom scheme name.
    NSURL *ourURL = [NSURL URLWithString:ourPath];                              //instead of our path you can directly write @"openapp"

     if ([ourApplication canOpenURL:ourURL]) 
         [ourApplication openURL:ourURL];
    else 
    {
        //Display error
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Receiver Not Found" message:@"The Receiver App is not installed." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
 // OR open link
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.urlForApp.com"]];
    }
}

// Now which app you want to open go its info.plist

1 Add a new row with name ----> URL types

2 Now in Item 0 add another object named ------> URL Schemes

3 Now at Item 0 of URL Schemes give the name through which you want to open your app for e.g @"openapp"

4 You have to write this in app delegate of the app you want to open

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url    {    return YES;    }


来源:https://stackoverflow.com/questions/24428697/shared-link-that-will-open-my-app-or-the-app-store

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