black1011
black1011

Reputation: 284

Detect if another application was installed/uninstalled in a jailbroken iDevice

I want to detect when another application was installed/uninstalled and save the time to a database at the moment of execution.

I know this is possible in Android using broadcastreceiver and I want to know if this can be done in iOS using a jailBroken device because I believe this is not possible in a non-jailBroken device.

I hope someone could help me. Thank you.

Upvotes: 1

Views: 1491

Answers (2)

Fouad
Fouad

Reputation: 409

You can check if an application is installed by using its bundle id

BOOL isInstalled = [[LSApplicationWorkspace defaultWorkspace] applicationIsInstalled:@"com.app.identifier"];

if (isInstalled) {
    // app is installed }
else {
    // app is not installed
}

EDIT:

If you want to check if an application got installed you can maybe count the items inside user of com.apple.mobile.installation.plist it holds all the information about installed apps.

You can write the number of apps inside a plist then later check back and compare the results?

// get apps count
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Caches/com.apple.mobile.installation.plist"];
int numberOfApps = [[dict objectForKey: @"User"] count];
NSLog(@"Count: %i",numberOfApps);

// Save apps count inside a plist
NSString *path = @"/var/mobile/AppsCount.plist"; 
NSFileManager *fm = [NSFileManager defaultManager];
NSMutableDictionary *data;
 if ([fm fileExistsAtPath:path]) {
     data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
}
else {
    // If the file doesn’t exist, create an empty dictionary
    data = [[NSMutableDictionary alloc] init];
}
[data setObject:[NSNumber numberWithInt:numberOfApps] forKey:@"savedAppsCount"];
[data writeToFile:path atomically:YES];
[data release];

And then to compare old counts with the new apps count:

// get current number of apps
NSString *path = @"/var/mobile/AppsCount.plist";
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Caches/com.apple.mobile.installation.plist"];
int numberOfApps = [[dict objectForKey: @"User"] count];

// retrieve old app count and compare to new ones
NSMutableDictionary *retrieveCounts = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
int oldAppCount = [[retrieveCounts objectForKey:@"savedAppsCount"] intValue];
if (oldAppCount < numberOfApps) { 
    NSLog(@"NEW APP GOT INSTALLED");
     }
else if (oldAppCount > numberOfApps) {
    NSLog(@"AN APP GOT UNINSTALLED");
}
else {
    NSLog(@"NOTHING GOT INSTALLED OR UNINSTALLED");
}
[retrieveCounts release];

But that doesn't give you the time, it just checks if a new app got installed

There might be a better way of doing that, but that's what came into my mind. Hope it helps.

Upvotes: 1

creker
creker

Reputation: 9580

Recently was having the same problem.

You need to write SpringBoard tweak. In it you observe notification SBInstalledApplicationsDidChangeNotification from local notification center (CFNotificationCenterGetLocalCenter or [NSNotificationCenter defaultCenter]). User info dictionary will contain:

  • SBInstalledApplicationsRemovedBundleIDs key contains array of bundle IDs of uninstalled applications.
  • SBInstalledApplicationsModifiedBundleIDs key contains array of bundle IDs of updated applications.
  • SBInstalledApplicationsAddedBundleIDs key contains array of bundle IDs of installed applications.

Obviously that way you can log every time applications are installed/uninstalled/updated.

Upvotes: 2

Related Questions