Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Is it possible to retrieve these information?

gibtanggibtang Posts: 91Registered Users
edited April 2012 in iPhone SDK Development
1) A list of apps that a user has installed on their device and app icons

or

2) A list of tunes on the device and then plays those tunes within the app

Anyone knows if these are possible?
Post edited by gibtang on
Try out my latest game <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=309557456&mt=8" target="_blank">Piecehunters Lite</a> for free<br />
<br />
Else get the <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/vie

Replies

  • BovnBovn Posts: 25Tutorial Authors
    edited July 2009
    The first one is not possible; all applications are installed in their own sandbox, meaning that they cannot do anything outside their own application. This is true for all scenarios, but certain things are allowed by Apple, such as retrieving the users image folder etc. But I'm not sure if it works when it comes to music. I do not think Apple are keen to have compeditors when it comes to their iPod.

    However, I'm not 100% sure about the first one, although it would surprise me a great deal if it was possible.
  • ShmoopiShmoopi Posts: 213Tutorial Authors, Registered Users
    edited July 2009
    Bovn wrote: »
    The first one is not possible; all applications are installed in their own sandbox, meaning that they cannot do anything outside their own application. This is true for all scenarios, but certain things are allowed by Apple, such as retrieving the users image folder etc. But I'm not sure if it works when it comes to music. I do not think Apple are keen to have compeditors when it comes to their iPod.

    However, I'm not 100% sure about the first one, although it would surprise me a great deal if it was possible.

    That's wrong, their is a way to check if an application is installed or not. Sometimes you may want to check if a specific app is installed on the device, in case you use custom URL schemes that require some other app to be installed (you could just gray out/disable some buttons then). Unfortunately, Apple apparently does not have any function that checks this for you, so I whipped one up. It does not enumerate every single app, instead it uses the MobileInstallation cache which is always up-to-date with SpringBoard and holds the Info dictionaries of all apps installed. Although you're not "supposed" to access the cache, it's readable my App Store apps. Here is my code which at least works perfectly fine with the Simulator:
    // 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.
    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);
    
    Log Output:
    2009-01-30 12:19:20.250 SomeApp[266:20b] App installed: com.apple.mobilesafari
    2009-01-30 12:19:20.254 SomeApp[266:20b] App installed: com.yourcompany.yourselfmadeapp
    2009-01-30 12:19:20.260 SomeApp[266:20b] App not installed: com.blahblah.nonexistent
    

    Your welcome:)
    Trackback for this code goes to:
    Code Sample: Check if an app is installed - iDevKit
    [SIGPIC][/SIGPIC]<br />
    <a href="http://www.shmoopi.net/" target="_blank">Check Out The Official Shmoopi LLC Website</a><br />
    <a href="http://itunes.apple.com/us/app/iprivatebrowser/id314281847?mt=8" target="_blank">iPrivateBrowser</a> | <a href="http:
  • smashersmasher Posts: 3,859Registered Users @ @ @ @ @
    edited July 2009
    I'd be surprised if this works on non-jailbroken phones. I think SandboxTemplate.sb prevents you from reading "/private/var/mobile/Applications/" except for your own folder.

    I'd test this on a device before relying on it.
    TinyCo is Hiring Mobile Game Programmers (C++)
    http://jobvite.com/m?3Ho5wgwr
  • ShmoopiShmoopi Posts: 213Tutorial Authors, Registered Users
    edited July 2009
    smasher wrote: »
    I'd be surprised if this works on non-jailbroken phones. I think SandboxTemplate.sb prevents you from reading "/private/var/mobile/Applications/" except for your own folder.

    I'd test this on a device before relying on it.

    Thanks for the concern, but yes it does, their are several apps that already utilize this. One of the most popular being Skype. It uses this to detect if it is running on a jailbroken device. The sandboxtemplate does not prevent it from reading a local file outside of the sandbox, only writing to it, unless it's on a jailbroken phone.
    [SIGPIC][/SIGPIC]<br />
    <a href="http://www.shmoopi.net/" target="_blank">Check Out The Official Shmoopi LLC Website</a><br />
    <a href="http://itunes.apple.com/us/app/iprivatebrowser/id314281847?mt=8" target="_blank">iPrivateBrowser</a> | <a href="http:
  • gibtanggibtang Posts: 91Registered Users
    edited July 2009
    Shmoopi wrote: »
    Thanks for the concern, but yes it does, their are several apps that already utilize this. One of the most popular being Skype. It uses this to detect if it is running on a jailbroken device. The sandboxtemplate does not prevent it from reading a local file outside of the sandbox, only writing to it, unless it's on a jailbroken phone.

    Thanks Shmoopi, this is a surprise as I thought that the iPhone SDK would disallow access. But your code works only if I know the bundle identifier. But if I do not know it, there is no way I can find out the bundle identifier of any app that is already installed in the device?

    Anyway, I went to the iPhone 3.0 OS SDK page at
    iPod Library Access - Get Ready for iPhone OS 3.0 - iPhone Developer Program

    and it mentions
    For example, you could create a trivia game that uses the metadata of the user’s songs. Improve on an arcade game by using a playlist as its soundtrack, or add the ability to listen to podcast lectures in a note taking app. You can make almost any app more enjoyable by bringing a user’s personal music and audio choices into your app.
    Try out my latest game <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=309557456&mt=8" target="_blank">Piecehunters Lite</a> for free<br />
    <br />
    Else get the <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/vie
  • BovnBovn Posts: 25Tutorial Authors
    edited July 2009
    Hm, I'm surprised :)

    @gibtang; Sure you can. If you check the code you can see that you load a dictionary from the plist named "com.apple.mobile.installation.plist". This code is intended to check if any given application you require is installed and therefore included in that dictionary, but you could just as easily extract the entire plist from what I can see and, say, display it in a UITableView. Why not print it out with NSLog() so that you can see the contents of it?
  • ShmoopiShmoopi Posts: 213Tutorial Authors, Registered Users
    edited July 2009
    Bovn wrote: »
    Hm, I'm surprised :)

    @gibtang; Sure you can. If you check the code you can see that you load a dictionary from the plist named "com.apple.mobile.installation.plist". This code is intended to check if any given application you require is installed and therefore included in that dictionary, but you could just as easily extract the entire plist from what I can see and, say, display it in a UITableView. Why not print it out with NSLog() so that you can see the contents of it?

    Can you give an example of this?
    [SIGPIC][/SIGPIC]<br />
    <a href="http://www.shmoopi.net/" target="_blank">Check Out The Official Shmoopi LLC Website</a><br />
    <a href="http://itunes.apple.com/us/app/iprivatebrowser/id314281847?mt=8" target="_blank">iPrivateBrowser</a> | <a href="http:
  • gibtanggibtang Posts: 91Registered Users
    edited July 2009
    Bovn wrote: »
    Hm, I'm surprised :)

    @gibtang; Sure you can. If you check the code you can see that you load a dictionary from the plist named "com.apple.mobile.installation.plist". This code is intended to check if any given application you require is installed and therefore included in that dictionary, but you could just as easily extract the entire plist from what I can see and, say, display it in a UITableView. Why not print it out with NSLog() so that you can see the contents of it?

    Hmm, ok. How about the app name itself? The one that appears below the icon?
    Try out my latest game <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=309557456&mt=8" target="_blank">Piecehunters Lite</a> for free<br />
    <br />
    Else get the <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/vie
  • BovnBovn Posts: 25Tutorial Authors
    edited July 2009
    I didn't try this snippet myself, but I did yesterday when trying to create a simple method to demonstrate what I mentioned earlier about retrieving the entire application list. Yet the code didn't work for me at all using the Simulator 3.0. There was no error, but I didn't get a dictionary at all.

    Does this really work for you guys?
    But, basically what I meant earlier was that in the code a dictionary is created with the contents of the file that -- according to the developer who wrote it -- contains all the info.plist data of each and every one of the applications installed. So instead of looping through an array of application bundle indicators as you do in the example, you could just manipulate the dictionary directly and show it in a UITableView.

    But I can't give you any code example since I couldn't make it work myself. Even without changing the code.
  • martinr_viennamartinr_vienna Posts: 7New Users
    edited July 2009
    Yes, the code only seems to work on pre-3.0 (it does at least on 2.2.1). It seems Apple does enforce the sandbox rules a bit stricter than previously. Although you can still access /var/mobile/Applications and get a listing of all the application directories - but those are in "08A9EF7A-8E49-4098-90F9-675CFC59208F" form. So unless somebodies knows how to get an appID out of this it's pretty useless.
  • rayhkleerayhklee Posts: 27Registered Users
    edited September 2009
    I am using the code provided, but I found that CacheDict : (null), there is no com.apple.mobile.installation.plist in the simulator
  • AngelAngel Posts: 52Registered Users
    edited April 2012
    Hi,

    I have the same requirement in my application. Tried with the sample code given above.But it didn't work both in simulator and device. Have tried with iHasApp API. But is not reliable as it doesn't list many apps. Can anyone give some ideas on this?

    Thanks in advance,
    angel.
Sign In or Register to comment.