user1310038
user1310038

Reputation: 97

How to check particular app is already installed on iphone device or not?

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

Upvotes: 0

Views: 1186

Answers (4)

Krishnan8190
Krishnan8190

Reputation: 320

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

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

Upvotes: 0

Apurv
Apurv

Reputation: 17186

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];

Upvotes: 0

Alexey
Alexey

Reputation: 7247

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

Upvotes: 1

elp
elp

Reputation: 8131

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

Upvotes: 0

Related Questions