且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式将文件夹添加到“地方"在Finder中

更新时间:2023-11-24 23:28:52

尝试一下:

-(void) addPathToSharedItem:(NSString *)path
{
    CFURLRef url = (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.
        LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(favoriteItems,
                                                                     kLSSharedFileListItemLast, NULL, NULL,
                                                                     url, NULL, NULL);
        if (item){
            CFRelease(item);
        }
    }   

    CFRelease(favoriteItems);
}