등록되어 있는지 확인 - runAtStartupEnabled
return.
BOOL
YES - 사용자 로그인 아이템에 해당 앱이 등록되어있음.
NO - 사용자 로그인 아이템에 해당 앱이 등록되어있지 않음.
Arguments.
없음.
code
- (BOOL)runAtStartupEnabled
{
NSURL *itemURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
Boolean foundIt=false;
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
if (loginItems)
{
UInt32 seed = 0U;
NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
for (id itemObject in currentLoginItems)
{
LSSharedFileListItemRef item = (LSSharedFileListItemRef)itemObject;
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
CFURLRef URL = NULL;
OSStatus err = LSSharedFileListItemResolve(item, resolutionFlags, &URL, NULL);
if (err == noErr)
{
foundIt = CFEqual(URL, itemURL);
CFRelease(URL);
if (foundIt)
{
break;
}
}
}
CFRelease(loginItems);
}
return (BOOL)foundIt;
}
등록 및 해제 - setRunAtStartupEnabled
return.
없음.
Arguments.
BOOL
YES - 사용자 로그인 아이템에 해당 앱을 등록
NO - 사용자 로그인 아이템에 해당 앱을 해제
code
- (void)setRunAtStartupEnabled:(BOOL)enabled
{
NSURL *itemURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
LSSharedFileListItemRef existingItem = NULL;
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
if(loginItems)
{
UInt32 seed = 0U;
NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
for (id itemObject in currentLoginItems)
{
LSSharedFileListItemRef item = (LSSharedFileListItemRef)itemObject;
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
CFURLRef URL = NULL;
OSStatus err = LSSharedFileListItemResolve(item, resolutionFlags, &URL, NULL);
if (err == noErr)
{
Boolean foundIt = CFEqual(URL, itemURL);
CFRelease(URL);
if (foundIt)
{
existingItem = item;
break;
}
}
}
if (enabled && (existingItem == NULL))
{
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst, NULL, NULL, (CFURLRef)itemURL, NULL, NULL);
}
else if(!enabled && (existingItem != NULL))
{
LSSharedFileListItemRemove(loginItems, existingItem);
}
CFRelease(loginItems);
}
}
Source.
http://stackoverflow.com/questions/5486447/leaks-enabling-and-disabling-runatstartupenabled
Tag.
Mac app 부팅시 자동 실행. 로그인시 자동 실행. 시작프로그램.
'Objective-c' 카테고리의 다른 글
NSString과 NSMutableString (0) | 2014.04.25 |
---|---|
AFNetworking download progressing (0) | 2014.04.25 |
NSString 문자열 치환 (0) | 2014.04.25 |
NSTimer (0) | 2014.04.25 |
코어 애니메이션 튜토리얼 페이지 (Core Animation Tutorial page) (0) | 2014.04.25 |
댓글