在使用NSRecentDocumentsMenu时,可以通过以下步骤来实现不需要Nib的Sandbox友好安装:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSMenu *recentDocsMenu = [[NSMenu alloc] initWithTitle:@"Recent Documents"];
[NSApp setRecentDocumentsMenu:recentDocsMenu];
}
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
// 打开文件的逻辑处理
return YES;
}
CFBundleDocumentTypes
CFBundleTypeExtensions
txt
rtf
CFBundleTypeName
Text Document
CFBundleTypeRole
Editor
LSHandlerRank
Owner
LSItemContentTypes
public.plain-text
public.rtf
通过以上步骤,您可以在没有Nib文件的情况下,实现一个Sandbox友好的NSRecentDocumentsMenu安装。请根据您的具体需求进行适当的修改和扩展。