删除app的缓存,同时把app移到trash
-(void)clearMemoryCache {
NSString* rootPath = @""//Cache path;
NSError* error = nil;
NSURL* trashUrl = nil;
// BOOL succ = [[NSFileManager defaultManager] removeItemAtPath:rootPath error:&error];
NSURL* fileUrl = [NSURL fileURLWithPath:rootPath]; [[NSFileManager defaultManager] trashItemAtURL:fileUrl resultingItemURL:&trashUrl error:&error];}
移到trash
-(void)moveToTrash {
NSError* error = nil;
NSURL* trashUrl = nil;
NSString* bundlePath = [NSBundle mainBundle].bundlePath;
NSURL* bundleUrl = [NSURL fileURLWithPath:bundlePath];
[[NSFileManager defaultManager] trashItemAtURL:bundleUrl resultingItemURL:&trashUrl error:&error];
[NSApp terminate:nil];
}
删除dock上的图标
- (void)removeFromDock {
NSMutableDictionary *dock = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:@"com.apple.dock"] mutableCopy];
NSMutableArray *dockApps = [[dock objectForKey:@"persistent-apps"] mutableCopy];
if (dockApps) {
for (int i=0; i < dockApps.count; i++) {
NSMutableDictionary *app = [dockApps[i] mutableCopy];
if ([[app valueForKeyPath:@"tile-data.bundle-identifier"] isEqualToString:@"identifier"]) {
// refresh dock
[dockApps removeObjectAtIndex:i];
[dock setObject:dockApps forKey:@"persistent-apps"];
[[NSUserDefaults standardUserDefaults] setPersistentDomain:dock
forName:@"com.apple.dock"];
[[NSUserDefaults standardUserDefaults] synchronize];
system("/usr/bin/killall Dock");
break;
}
}
}
}