2011-03-27 2 views
5

내가 코코아 애플리케이션이 어떻게 글로벌 로그인 항목으로 추가 될 수 있습니까? 내가 만든 응용 프로그램을 실행할 때

LSSharedFileListRef globalLoginItems = LSSharedFileListCreate(NULL, kLSSharedFileListGlobalLoginItems, NULL); 
if (globalLoginItems) { 
    LSSharedFileListItemRef ourLoginItem = LSSharedFileListInsertItemURL(globalLoginItems, 
                     kLSSharedFileListItemLast, 
                     NULL, NULL, 
                     (CFURLRef)[[NSBundle mainBundle] bundleURL], 
                     NULL, NULL); 
    if (ourLoginItem) { 
     CFRelease(ourLoginItem); 
    } else { 
     NSLog(@"Could not insert ourselves as a global login item"); 
    } 

    CFRelease(globalLoginItems); 
} else { 
    NSLog(@"Could not get the global login items"); 
} 

LSSharedFileListInsertItemURL

시도()는 단지 NULL을 반환했습니다. 내가해야 할 일이 있니? 어떤 종류의 허가?

참고 : 여기의 유스 케이스는 kLSSharedFileListGlobalLoginItems가 아닌 kLSSharedFileListSessionLoginItems를 사용하는 글로벌 로그인 항목입니다.

답변

5

이 작업이 있습니다. LSSharedFileListSetAuthorization에 대한

AuthorizationRef auth = NULL; 
AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth); 
LSSharedFileListSetAuthorization(globalLoginItems, auth); 

워드 프로세서 우리가 바로 이것에 대한 system.global-login-items를 얻을 수 있다고 말하지만, 그럼에도 불구하고 일 : 내가했던 일은, 내가 응용 프로그램을 삽입하기 전에 로그인 항목에이 줄을 추가했다!

그러나 사용자가 관리자가 아닌 경우이 작업은 실패합니다. 너무 후 작동하려면이 작업을 수행해야합니다 :

AuthorizationItem right[1] = {{"system.global-login-items.", 0, NULL, 0}}; 
AuthorizationRights setOfRights = {1, right}; 
AuthorizationRef auth = NULL; 
AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth); 


AuthorizationCopyRights(auth, &setOfRights, kAuthorizationEmptyEnvironment, 
           (kAuthorizationFlagDefaults 
           | kAuthorizationFlagInteractionAllowed 
           | kAuthorizationFlagExtendRights), NULL); 

또한 자세한 내용은 the docs를 참조하는 것이 바람직합니다.

1

이 나를 위해 작동합니다

NSString * appPath = [[NSBundle mainBundle] bundlePath]; 

// This will retrieve the path for the application 
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath]; 

// Create a reference to the shared file list. 
// We are adding it to the current user only. 
// If we want to add it all users, use 
// kLSSharedFileListGlobalLoginItems instead of 
//kLSSharedFileListSessionLoginItems 
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL); 
if (loginItems) { 
    //Insert an item to the list. 
    LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,kLSSharedFileListItemLast, NULL, NULL,url, NULL, NULL); 
    if (item){ 
     CFRelease(item); 
    } 
} 

CFRelease(loginItems); 
+0

감사합니다. kLSSharedFileListSessionLoginItems도 저에게 적합합니다. 나는 이것을 모든 사용자에게 적용하기를 원합니다. kLSSharedFileListGlobalLoginItems를 사용합니다. – Plumenator

0
NSString * appPath = [[NSBundle mainBundle] bundlePath]; 

     // This will retrieve the path for the application 
     CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath]; 

     LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListGlobalLoginItems, NULL); 
     if (loginItems) { 
      //Insert an item to the list. 
      LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(loginItems,kLSSharedFileListItemLast, NULL, NULL,url, NULL, NULL); 
      if (item){ 
       CFRelease(item); 
      } 
     } 

     CFRelease(loginItems); 

이 코드를 작동하지 않습니다? kLSSharedFileListSessionLoginItems를 kLSSharedFileListGlobalLoginItems로 바 꾸었습니다.

+0

맞습니다. 항목을 NULL로 가져옵니다. – Plumenator

관련 문제