Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-09-2010, 07:21 AM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 80
laurensjuhh325 is on a distinguished road
Default Checking if app is installed

Hello everyone, I'm trying to find a way how to check if an app is installed.
This used to work:
Code:
// Declaration
BOOL APCheckIfAppInstalled(NSString *bundleIdentifier); // Bundle identifier (eg. com.apple.mobilesafari) used to track apps

// Implementation

BOOL APCheckIfAppInstalled(NSString *bundleIdentifier)
{
	static NSString *const cacheFileName = @"com.apple.mobile.installation.plist";
	NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName];
	NSDictionary *cacheDict = nil;
	NSString *path = nil;
	// Loop through all possible paths the cache could be in
	for (short i = 0; 1; i++)
	{
	
		switch (i) {
	case 0: // Jailbroken apps will find the cache here; their home directory is /var/mobile
		path = [NSHomeDirectory() stringByAppendingPathComponent: relativeCachePath];
		break;
	case 1: // App Store apps and Simulator will find the cache here; home (/var/mobile/) is 2 directories above sandbox folder
		path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: relativeCachePath];
		break;
	case 2: // If the app is anywhere else, default to hardcoded /var/mobile/
		path = [@"/var/mobile" stringByAppendingPathComponent: relativeCachePath];
		break;
	default: // Cache not found (loop not broken)
		return NO;
		break; }
		
		BOOL isDir = NO;
		if ([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory: &isDir] && !isDir) // Ensure that file exists
			cacheDict = [NSDictionary dictionaryWithContentsOfFile: path];
		
		if (cacheDict) // If cache is loaded, then break the loop. If the loop is not "broken," it will return NO later (default: case)
			break;
	}
	
	NSDictionary *system = [cacheDict objectForKey: @"System"]; // First check all system (jailbroken) apps
	if ([system objectForKey: bundleIdentifier]) return YES;
	NSDictionary *user = [cacheDict objectForKey: @"User"]; // Then all the user (App Store /var/mobile/Applications) apps
	if ([user objectForKey: bundleIdentifier]) return YES;
	
	// If nothing returned YES already, we'll return NO now
	return NO;
}
Here is an example of this, assuming that your app is named "yourselfmadeapp" and is an app in the app store. 
Code:
NSArray *bundles2Check = [NSArray arrayWithObjects: @"com.apple.mobilesafari", @"com.yourcompany.yourselfmadeapp", @"com.blahblah.nonexistent", nil];
for (NSString *identifier in bundles2Check)
	if (APCheckIfAppInstalled(identifier))
		NSLog(@"App installed: %@", identifier);
	else
		NSLog(@"App not installed: %@", identifier);
But somehow it fails on my jailbroken ipad 3.2.1.
This is an app for personal use. I'm not sending this to apple so it doesn't matter if it violates the rules.

Any thoughts?
Thanks!
laurensjuhh325 is offline   Reply With Quote
Old 08-09-2010, 07:48 AM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 80
laurensjuhh325 is on a distinguished road
Default

Please, anyone?
laurensjuhh325 is offline   Reply With Quote
Old 08-09-2010, 11:21 AM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

you can use the openURL from UIApplication to try and open the app. Assume it is installed, and if the call fails, or a certain time passes then you can assume its not installed.
smithdale87 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 342
11 members and 331 guests
arash5500, HemiMG, iram91419, linkmx, mediaspree, nadav@webtview.com, Objective Zero, Paul Slocum, stanny, Touchmint, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:37 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0