一担败、菜單欄設(shè)置開(kāi)機(jī)自動(dòng)啟動(dòng)
原文鏈接:https://blog.csdn.net/lovechris00/article/details/81483108
- (void)setLaunchAgents{
NSString* launchFolder = [NSString stringWithFormat:@"%@/Library/LaunchAgents",NSHomeDirectory()];
NSString * bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleIdentifierKey];
NSString* dstLaunchPath = [launchFolder stringByAppendingFormat:@"/%@.plist",bundleID];
NSLog(@"dstLaunchPath : %@",dstLaunchPath);
//dstLaunchPath : /Users/administrator/Library/LaunchAgents/com.melissashu.www.MSLaunchAgentsLogin.plist
NSFileManager* fm = [NSFileManager defaultManager];
BOOL isDir = NO;
//已經(jīng)存在啟動(dòng)項(xiàng)中,就不必再創(chuàng)建
if ([fm fileExistsAtPath:dstLaunchPath isDirectory:&isDir] && !isDir) {
return;
}
//下面是一些配置
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
NSMutableArray* arr = [[NSMutableArray alloc] init];
[arr addObject:[[NSBundle mainBundle] executablePath]];
[arr addObject:@"-runMode"];
[arr addObject:@"autoLaunched"];
[dict setObject:[NSNumber numberWithBool:true] forKey:@"RunAtLoad"];
[dict setObject:bundleID forKey:@"Label"];
[dict setObject:arr forKey:@"ProgramArguments"];
isDir = NO;
if (![fm fileExistsAtPath:launchFolder isDirectory:&isDir] && isDir) {
[fm createDirectoryAtPath:launchFolder withIntermediateDirectories:NO attributes:nil error:nil];
}
NSLog(@"dict : %@",dict);
[dict writeToFile:dstLaunchPath atomically:NO];
}
其他參考方式:
http://www.reibang.com/p/19e95619c6a6
二状婶、運(yùn)行后隱藏Dock上的圖標(biāo)
設(shè)置info.plist 文件湾盗,添加Application is Agent 設(shè)置為yes