4

I am doing one iOS application. In that, I have one module for UITableView. In that UITableView, I am displaying some list of apps names. Those names are coming from my server. Those are my company applications. So, i don't know how many apps would come from server. Once user clicks on the UITableViewCell, I need to check whether that apps already installed or not on that device. If not installed, user needs to goes to appstore using app store link of that app. I have checked some tutorials. In that they said, using url schemes we can do this scenario. But, i don't have url schemes for those urls, because those apps are coming from server. Also, I tried with following methods

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms://itunes.com/apps/nameOfMyApp"]]; 
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"nameOfMyAppOrurl:"]];

but nothing helped me. Can anyone idea about this issue, if so please give your valuable suggestions.

4 Answers4

4

You will need to have a App URL scheme for each app in the list, there is no other way to check whether the app is installed.

I'm guess the list form you server will be in JSON, something like:

{
   "name" : "My Cool APP",
   "scheme" :"mycoolapp:",
   "itunes": "http:///...../"
}

Then just do something like:

    if ([[UIApplication sharedApplication] canOpenURL:scheme]) {
        [[UIApplication sharedApplication]openURL:scheme];
    }
    else {
        [[UIApplication sharedApplication]openURL:itunesURL];
    }
rckoenes
  • 69,092
  • 8
  • 134
  • 166
2

Custom url schemes is the preferred way to solve this issue. You have to know all url schemes (that means that all the apps should have one configured) for each app you need to check availability for. For your specific case, you'll need a backend support, i.e. server should provide a scheme for each app (server should be informed about the schemes as well).

Another option is using shared data in keychain, there's an answer here about sharing data between apps via keychain. You should think up a solution for that, but as long as you can share data between known group of apps, you can implement something on top of that technique. Note that second solution requires you to own all the apps (or be able to affect their configuration).

Community
  • 1
  • 1
MANIAK_dobrii
  • 6,014
  • 3
  • 28
  • 55
1

You can registering a custom URL Scheme for application at server: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50

if your app have scheme, you will able to use canOpenURL method.

zhukov.ever
  • 557
  • 3
  • 10
0

You can also assign URL Schemes to your company Apps, and check whether they are installed using following code:

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"myAppURLScheme://"]])
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myAppURLScheme://"]];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App not installed on Device"  delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Open link", nil];
    [alert show];
}

Also check this URL Scheme Tutorial

Meet
  • 4,904
  • 3
  • 24
  • 39
  • hi Meet, thanks for your quick reply. I have one doubt, how to pass app name to plist of app for creating custom url scheme? – Anilkumar iOS - ReactNative Jul 30 '14 at 10:45
  • @Anilkumar, Open your code in Xcode, Go to Targets. In the "Info" Tab below, set URL Types, give bundle identifier and your Desired url scheme. Also check the URL scheme tutorial link i gave in my answer – Meet Jul 30 '14 at 12:14
  • bundle id is okay, but how to add appnameinfo.plist for url scheme in runtime, because i am getting app names from server runtime oonly, i hope you can understand my issue – Anilkumar iOS - ReactNative Jul 31 '14 at 06:20
  • @Anilkumar, You don't need add url scheme @ runtime. What I am telling is to use the above code for checking whether the urlscheme is supported to open an App or not. Say, you are getting "testAppOne://" URL Scheme, which is also an App from you company. All you need is to check whether that particular app is installed on device or not using above code. i don't understand why you are asking to set dynamic URL Scheme. FYI, you cannot set dynamic URL scheme. – Meet Jul 31 '14 at 10:03
  • will this open that app after executing this `[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myAppURLScheme://"]];`. I want app should not be opened – N Sharma Apr 05 '15 at 14:47