Mac OSX 打开功能不工作

Mac OSX open With function not working

我想在我的应用程序中使用“打开方式”功能打开一个图像文件,但它打不开 这是 xcode 设置

xcode Plist settings

这里是appdelegate的代码

App Delegate Code

@property (assign) NSMutableArray *_allFiles ;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
    if (_allFiles.count >0)
    {
        [self openFiles:[_allFiles objectAtIndex:0]];
    }
    self.homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    [self.window.contentView addSubview:self.homeViewController.view];
    self.homeViewController.view.frame = ((NSView*)self.window.contentView).bounds;
}

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
    [self application:theApplication openFiles:[NSArray arrayWithObject:filename]];
    [self.homeViewController ShowAlert:filename];
    NSLog(@"====%@",filename);
    return YES;
}
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames {
    if(!_allFiles)
    {
        _allFiles = [NSMutableArray arrayWithCapacity:1];
    }
    [_allFiles addObjectsFromArray:filenames];
}

如果您想打开 'Supported Files' 文件夹中的文件,您必须说:

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"/Applications/YourApp.app/Contents/Resources/YourFile.extension"]];

用您的应用替换 YourApp.app
YourFile.extension 替换为您的图片。

注:
这仅在您的应用程序位于您的应用程序文件夹中时才有效。
如果不是,您必须更改路径或将您的应用程序放在那里。