app 注冊開機 啟動
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
//url為app所在的目錄
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemLast, NULL, NULL, url, NULL, NULL);
CFRelease(item);
CFRelease(loginItems);
app取消自動啟動的 注冊
UInt32 seedValue;
CFURLRef thePath;
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
CFArrayRef loginItemsArray = LSSharedFileListCopySnapshot(loginItems, &seedValue);
for (id item in (NSArray *)loginItemsArray) {
LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)item;
if (LSSharedFileListItemResolve(itemRef, 0, (CFURLRef*) &thePath, NULL) == noErr) {
//appPath目錄為要取消開機啟動app的路徑
if ([[(NSURL *)thePath path] hasPrefix:appPath])
{
LSSharedFileListItemRemove(theLoginItemsRefs, itemRef); // 删除指定的啟動項
}
CFRelease(thePath);
}
}
CFRelease(loginItemsArray);
CFRelease(loginItems);