简体   繁体   English

cocoa使用关联的应用程序打开多个文件

[英]cocoa open multiple files with associated app

I have an array of filenames that i would like to pass to an external application for opening. 我有一个文件名数组,我想传递给外部应用程序打开。 I'd like to do one of the following: 我想做以下其中一项:

a) Somehow instruct OSX to open all these files with an associated application, but it must invoke the target app's openFiles NSApplication delegate method b) Specify the application to open these files with (and also invoke openFiles) a)以某种方式指示OSX使用关联的应用程序打开所有这些文件,但它必须调用目标应用程序的openFiles NSApplication委托方法b)指定应用程序以打开这些文件(并调用openFiles)

Basically it doesn't matter which solution to realise, because these files will be associated with the target application anyway. 基本上要实现哪个解决方案并不重要,因为无论如何这些文件都将与目标应用程序相关联。 How would i do one of these things? 我怎么做这些事情之一?

To open a whole bunch of files at once, send the shared NSWorkspace object an openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers: message , or call the LSOpenURLsWithRole function or the LSOpenFromURLSpec function . 要一次打开一大堆文件,请将共享的NSWorkspace对象发送到openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers: message ,或者调用LSOpenURLsWithRole函数LSOpenFromURLSpec函数 Either way, you'll pass an array of URLs to items to open. 无论哪种方式,您都会将一系列URL传递给要打开的项目。

Each one of these will let you identify a specific application to use. 其中每个都可以让您识别要使用的特定应用程序。 NSWorkspace lets you specify it by bundle identifier, while the two Launch Services functions let you provide the URL or FSRef to a specific application bundle. NSWorkspace允许您通过包标识符指定它,而两个启动服务功能允许您将URL或FSRef提供给特定的应用程序包。

… it must invoke the target app's openFiles NSApplication delegate method ...它必须调用目标应用程序的openFiles NSApplication委托方法

That isn't possible to require, because (a) the application may be document-based, in which case it probably does not have an NSApplication delegate and, even if it does, such a delegate would probably not respond to application:openFiles: , and (b) the application may not be Cocoa-based, in which case it would handle the Open Documents Apple Event directly. 这是不可能要求的,因为(a)应用程序可能是基于文档的,在这种情况下它可能没有NSApplication委托,即使它确实如此,这样的委托可能不会响应application:openFiles: ,(b)该应用程序可能不是基于Cocoa的,在这种情况下,它将直接处理Open Documents Apple Event。 None of this is your application's business, so don't worry about it. 这些都不是您的应用程序的业务,所以不要担心它。

First add your video files to Resources Folder.The code like follow: 首先将您的视频文件添加到资源文件夹。代码如下:

NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
NSString* videoPath = [bundlePath stringByAppendingPathComponent:@"/Contents/Resources/video.mov"];

[[NSWorkspace sharedWorkspace] openFile:videoPath];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM