我曾经认为文件夹需要有一个扩展名,以便Finder将它们识别为包.该扩展将在拥有应用程序的Info.plist中声明.
显然还有另一种更优雅的方式,但我无法弄清楚它是如何完成的.
例如,Finder将iPhoto图库视为包.但它没有延伸.mdls显示它确实在内容类型树中有"com.apple.package".实际内容类型是动态分配的.
iPhoto如何创建这样的目录?
虽然你不应该完全依赖它,但要做的一件事是设置文件的bundle位.我在NSWorkspace上有一个类别可以做到这一点:
- (void)setBundleBit:(BOOL)flag forFile:(NSString *)path
{
FSRef fileRef;
OSErr error = FSPathMakeRef((UInt8 *)[path fileSystemRepresentation], &fileRef, NULL);
// Get the file's current info
FSCatalogInfo fileInfo;
if (!error)
{
error = FSGetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &fileInfo, NULL, NULL, NULL);
}
if (!error)
{
// Adjust the bundle bit
FolderInfo *finderInfo = (FolderInfo *)fileInfo.finderInfo;
if (flag) {
finderInfo->finderFlags |= kHasBundle;
}
else {
finderInfo->finderFlags &= ~kHasBundle;
}
// Set the altered flags of the file
error = FSSetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &fileInfo);
}
if (error) {
NSLog(@"OSError %i in -[NSWorkspace setBundleBit:forFile:]", error);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1247 次 |
最近记录: |