“打开最近使用的菜单”仅在XCode中有效
我正在一个非NSDocument应用程序中实现“最近打开”菜单 在通过NSOpenPanel获取文件的url(其中包含文件的完整路径)后,应用程序会继续打开文件并访问它,然后应用程序会: [[NSDocumentController sharedDocumentController]noteNewRecentDocumentURL:self.URLFile] 这将添加文件以打开最近的菜单,此时一切正常 当我尝试通过“打开最近”菜单打开文件时,应用程序会:“打开最近使用的菜单”仅在XCode中有效,xcode,nsurl,Xcode,Nsurl,我正在一个非NSDocument应用程序中实现“最近打开”菜单 在通过NSOpenPanel获取文件的url(其中包含文件的完整路径)后,应用程序会继续打开文件并访问它,然后应用程序会: [[NSDocumentController sharedDocumentController]noteNewRecentDocumentURL:self.URLFile] 这将添加文件以打开最近的菜单,此时一切正常 当我尝试通过“打开最近”菜单打开文件时,应用程序会: (BOOL)应用程序:(NSAppli
- (BOOL)应用程序:(NSApplication*)应用程序打开文件:(NSString*)文件名
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
// paths in NSDocumentController recentDocumentURLs array
NSLog(@"Paths in recentDocumentURLs");
for (NSURL *url in [NSDocumentController sharedDocumentController].recentDocumentURLs) {
NSLog(@"Path: %@",[url absoluteString]);
}
NSLog(@"Path filename: %@", filename);
NSString *temp = [filename stringByExpandingTildeInPath];
NSLog(@"Path temp: %@", temp);
self.archivoURL = [NSURL fileURLWithPath:filename isDirectory:NO];
NSLog(@"Path self.archivoURL: %@", self.archivoURL);
if (self.archivoURL == nil) return NO;
// open file...
return YES;
} // Fin de application:OpenFile
XCode日志中的此代码:
Paths in recentDocumentURLs
2016-12-21 00:08:23.118577 AppMake[9424:253018] Path: file:///Users/Manuel/Documents/Modelos%203D/X_single_Ring_round_40.stl
2016-12-21 00:08:23.118612 AppMake[9424:253018] Path: file:///Users/Manuel/Documents/Modelos%203D/pirinola.stl
2016-12-21 00:08:23.118625 AppMake[9424:253018] Path: file:///Users/Manuel/Documents/Modelos%203D/cubo%203.stl
2016-12-21 00:08:23.118636 AppMake[9424:253018] Path filename: /Users/Manuel/Documents/Modelos 3D/cubo 3.stl
2016-12-21 00:08:23.118665 AppMake[9424:253018] Path temp: /Users/Manuel/Documents/Modelos%203D/cubo%203.stl
2016-12-21 00:08:23.118706 AppMake[9424:253018] Path self.archivoURL: file:///Users/Manuel/Documents/Modelos%203D/cubo%203.stl
此代码位于XCode外部,并通过Terminal.app启动应用程序以查看日志,日志:
2016-12-21 00:08:05.564 AppMake[9410:252746] Paths in recentDocumentURLs
2016-12-21 00:08:05.566 AppMake[9410:252746] Path: file:///Users/Manuel/Documents/Modelos%203D/X_single_Ring_round_40.stl
2016-12-21 00:08:05.566 AppMake[9410:252746] Path: file:///Users/Manuel/Documents/Modelos%203D/pirinola.stl
2016-12-21 00:08:05.566 AppMake[9410:252746] Path: file:///Users/Manuel/Documents/Modelos%203D/cubo%203.stl
2016-12-21 00:08:05.566 AppMake[9410:252746] Path filename: /Users/Manuel/Documents/Modelos 3D/cubo 3.stl
2016-12-21 00:08:05.566 AppMake[9410:252746] Path temp: /Users/Manuel/Documents/Modelos%203D/cubo%203.stl
2016-12-21 00:08:05.566 AppMake[9410:252746] Path self.archivoURL: (null)
有什么想法吗
谢谢Manuel您是否检查了沙盒权限?应用程序是否适用于appstore?当你接受了之前问题的答案时,它也会帮助你找到新的答案:-)嗨。很抱歉,没有标记为已接受答案。在我以前的岗位上做这件事(是的,应用程序是针对AppStore的沙盒,位于authorigents.plist I set com.apple.security.files.user-selected.read-write中。您可能必须将最近的URL(通常为NSUserDefaults)存储为安全范围的书签。