0

How to check particular app is already installed on iphone device or not? How we can achieve this any idea?

user1310038
  • 97
  • 2
  • 3
  • 10

4 Answers4

1

canOpenURL is the essentially checks whether the app that is registered to that particular URL scheme is installed or in other words if the app exists, and if it is, we can open the URL.

- (BOOL) appExists: (NSURL*)url{
    if ([[UIApplication sharedApplication] canOpenURL:url]) {        
        return YES;

    } else {
        return NO;
    }
}


NSURL *urlApp = [NSURL URLWithString:@"fb://profile/73728918115"];// facebook app

NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:@"%@", @"twitter:///user?screen_name=INNOVA_ET_BELLA"]];//tweeter app

if ([self appExists:urlApp]) {
        [[UIApplication sharedApplication] openURL:urlApp];
} 

IPhone URL Schemes:

http://wiki.akosma.com/IPhone_URL_Schemes

Custom URL Schemes:

http://mobiledevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
Alexey
  • 7,127
  • 9
  • 57
  • 94
  • 1
    This only works if the app has a registered and known URL scheme set up. – Martin Jul 31 '12 at 09:25
  • what do you bother to register it? http://mobiledevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html – Alexey Jul 31 '12 at 09:29
0

using below code you can retrieve the list of all applications.

 NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
 NSString *sandBoxPath = [bundleRoot stringByDeletingLastPathComponent];
 NSString *appFolderPath = [sandBoxPath stringByDeletingLastPathComponent];

 NSFileManager *fm = [NSFileManager defaultManager];
 NSArray *dirContents = [fm contentsOfDirectoryAtPath:appFolderPath error:nil];

 NSMutableArray *appNames = [[NSMutableArray alloc]init];
 for(NSString *application in dirContents)
 {
      NSString *appPath = [appFolderPath stringByAppendingPathComponent:application];
      NSArray *appcontents = [fm contentsOfDirectoryAtPath:appPath error:nil];
      NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.app'"];
      NSArray *onlyApps = [appcontents filteredArrayUsingPredicate:fltr];
      if(onlyApps.count > 0)
           [appNames addObject:[onlyApps objectAtIndex:0]];
 }

 NSLog(@"%@", [appNames description]);
 [appNames release];
Apurv
  • 17,116
  • 8
  • 51
  • 67
0

If the app has a registered URL you can check if exist in this way

[[UIApplication sharedApplication] canOpenURL:url]

URL is something like skype://

if not, you need to loop in all folders.
Here how to: Getting a list of files in a directory with a glob

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];
NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.app'"];
NSArray *onlyAPPs = [dirContents filteredArrayUsingPredicate:fltr];

Applications are located in /var/application/APPNAME.app (if i remember well).

Community
  • 1
  • 1
elp
  • 8,021
  • 7
  • 61
  • 120
0

Here's an example to test if the facebook app is installed.

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
// Facebook app is installed
 }
Krishnan8190
  • 320
  • 2
  • 8