2013-04-16 2 views
3

LSSharedFileListInsertItemURL 문제가 있습니다. 위대한 작품을 Finder 사이드 바에 항목을 추가하려고합니다. 그것이 수행하지 않는 유일한 작업은 사이드 바에서 항목의 이름을 변경하는 것입니다. 인수로 "FolderName"을 밀고 있지만이 함수를 실행하면 항목의 이름이 변경되지 않습니다. 이름으로 잠시 깜박이지만 실제 이름으로 빠르게 변경됩니다. 나는 이것에 대한 해결책을 찾기 위해 가능한 한 많은 것을 수색했으며 아무 것도 생각해 내지 못했다. 누구든지 내 코드에 문제가 있거나이를 작동시키기 위해 "해킹"이 있으면 알려 주시기 바랍니다.LSSharedFileListInsertItemURL 이름을 변경하지 않습니다.

-(void) addPathToSharedItem:(NSString *)path 
{ 

    CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path]; 

    // Create a reference to the shared file list. 
    LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL); 

    if (favoriteItems) { 

     //Insert an item to the list. 
     CFStringRef mdcName = CFSTR("FolderName"); 

     LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems, kLSSharedFileListItemLast, mdcName, NULL, url, NULL, NULL); 

     if (item){ 

      CFRelease(item); 
     } 
    } 

    CFRelease(favoriteItems); 
} 
+0

왜 당신은 추가 직후 항목을 제거합니까 : (죄송하지만, 쉽게 목표 C에 이식 할 수 ++ C에서)

다음 코드는이 구현? 그리고 왜 두 번리스트를 작성합니까? – JWWalker

+0

죄송합니다. 몇 사람을 테스트 해 보았습니다. 그들은 제거되었습니다. –

답변

1

는 [나는이 질문은 오래 전에 질문을 받았다 알고 있지만, 더 적절한 대답은 다른 곳에서 찾을 수 있습니다 나타납니다.]은 LSSharedFileListInsertItemURL 실제로 알려진 버그 reported to Apple in 2013 후 즐겨 찾기 이름을 새로 고침

찾기 없습니다.

다른 폴더를 즐겨 찾기에 수동으로 추가하면 즐겨 찾기 섹션이 새로 고쳐지고 LSSharedFileListInsertItemURL을 통해 이전에 설정된 적절한 이름이 표시됩니다.

매우 더러운 해결 방법은 단순히 다른 항목을 삽입 한 다음 즉시 삭제하여이를 자동화하는 것입니다.

// Create a reference to the shared file list. 
LSSharedFileListRef favoriteItems = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL); 
if (!favoriteItems) 
    return false; 

//Insert an item to the list. 
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems, //Insert in this list 
                  kLSSharedFileListItemBeforeFirst, //Here 
                  (CFStringRef) shortCurtNameNS, //Shortcut name 
                  NULL, //Icon 
                  url, //URL/path 
                  NULL, 
                  NULL); 
if (item) 
    CFRelease(item); 


// Here it goes dark. Really dark. 
// Finder does not refresh Favorites until another one is inserted "manually". 
// The following lines just emulates this : insert another item then immediately remove it. This will refresh favs. 
// KarmaPoints--; 
CFURLRef dummy = (__bridge CFURLRef)[NSURL fileURLWithPath:@"/"]; 
NSString * dummyName = [NSString stringWithCString:"Root" encoding:[NSString defaultCStringEncoding]]; 
LSSharedFileListItemRef dummyItem = LSSharedFileListInsertItemURL(favoriteItems, //Insert in this list 
                  kLSSharedFileListItemLast, //Here 
                  (CFStringRef) dummyName, //Shortcut name 
                  NULL, //Icon 
                  dummy, //URL/path 
                  NULL, 
                  NULL); 
// Remove it 
LSSharedFileListItemRemove(favoriteItems, dummyItem); 
if (dummyItem) 
    CFRelease(dummyItem); 
+0

응답 해 주셔서 감사합니다. 우리는 이와 비슷한 일을 끝내지 만 프로젝트는 결국 자금을 잃어 버렸고 폐쇄되었습니다 (공립 학교 시스템 임)! –

관련 문제