Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check whether application is installed or not in iOS device?

Tags:

xcode

ios

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.

like image 657
Anilkumar iOS - ReactNative Avatar asked Mar 19 '23 21:03

Anilkumar iOS - ReactNative


2 Answers

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];
    }
like image 83
rckoenes Avatar answered May 07 '23 06:05

rckoenes


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).

like image 24
MANIAK_dobrii Avatar answered May 07 '23 07:05

MANIAK_dobrii