2015 年の更新
LSSharedFileListヘッダーには、これが CoreServices フレームワークに移動したことが示されています。実際、(Xcode で) Cmd-Shift-O を押して LSSharedFileList と入力し、唯一の結果に移動すると、ジャンプ バーにヘッダーが実際に含まれていることがわかりますCoreServices.framework。いずれにせよ、キーはまだkLSSharedFileListFavoriteItemsです。
例:
+ (BOOL)appendFavoriteItemWithURL:(NSURL *)url {
// Pessimism ...
BOOL result = NO;
// Do we have a file URL?
if (url.isFileURL) {
// Ask CoreServices for the favorite items list
// (kLSSharedFileListFavoriteItems)
LSSharedFileListRef list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
if (list) {
// We've got the list, so try to append our item
// (use kLSSharedFileListItemBeforeFirst vs.
// kLSSharedFileListItemLast if desired)
LSSharedFileListItemRef item = LSSharedFileListInsertItemURL(list,
kLSSharedFileListItemLast,
NULL,
NULL,
(__bridge CFURLRef)url,
NULL,
NULL);
// Did it work?
if (item) {
// Release the item and flag success
CFRelease(item);
result = YES;
}
// Release the list
CFRelease(list);
}
}
return result;
}
使用法:
// Create the path to the favorite item to add
NSString * itemPath = [@"~/Music" stringByExpandingTildeInPath];
NSURL * itemURL = [NSURL fileURLWithPath:itemPath];
// Insert the item
[WhateverClassTheAboveFunctionIsIn appendFavoriteItemWithURL:itemURL];