objective c - Cocoa/Obj-C - Open file when dragging it to application icon -


At this time, there is a button on my app infograph, which allows to open a file, this is my open code:

My app.h:

  - (IBAction) Select File: (ID) Sender;   

In my app.m:

  @ synthesis window; - (blank) ApplicationDefinition Launching: (NSNetification *) An Information {} - Select (IBAction) File: (ID) Sender {NSOPPANEL * OpenPANEL = [NSOPPANEL OPENPENNEL]; NSArray * fileTypes = [Object with NSArray array: @ "xml", zero]; NSInteger result = [openPanel runModalForDirectory: NSHomeDirectory () file: zero type: fileTypes]; If (result == NSOKButton) {NSString * input = [openPanel filename];   

I would like to drag my code into an app-icon & amp; Drop?
Note: I have edited the .plist file and added a line for "xml" but it changes anything, gets an error when my file is dropped on the icon
note 2: i In the select file, "File -> Open ..." is linked: Check my code - Note 3: My app is not a document-based application

Thank you for your help! First, add the appropriate extensions to CFBundleDocumentTypes inside the .plist file. First, add the appropriate extension to the CFBundleDocumentTypes inside the .plist file.

Next apply the following delegates:
- Application: Openfile: (file dropped)
Applications: OpenFile: (multiple files deleted)
< / P>

Reference:

Feedback to the comment:

Step by step, hopefully it clarifies everything Is :)

. Plist file:

  & lt; Key & gt; CFBundleDocumentTypes & lt; / Key & gt; & Lt; Array & gt; & Lt; Dict & gt; & Lt; Key & gt; CFBundleTypeExtensions & lt; / Key & gt; & Lt; Array & gt; & Lt; String & gt; XML & lt; / String & gt; & Lt; / Array & gt; & Lt; Key & gt; CFBundleTypeIconFile & lt; / Key & gt; & Lt; String & gt; Application.icns & lt; / String & gt; & Lt; Key & gt; CFBundleTypeMIMETypes & lt; / Key & gt; & Lt; Array & gt; & Lt; String & gt; Text / xml & lt; / String & gt; & Lt; / Array & gt; & Lt; Key & gt; CFBundleTypeName & lt; / Key & gt; & Lt; String & gt; XML file & lt; / String & gt; & Lt; Key & gt; CFBundleTypeRole & lt; / Key & gt; & Lt; String & gt; Viewer & lt; / String & gt; & Lt; Key & gt; LSIsAppleDefaultForType & lt; / Key & gt; & Lt; True /> & Lt; / Dict & gt; & Lt; / Array & gt; Add to   

... AppDelegate.h - (BOOL) processFile: (NSString *) file; - (IBAction) openFile manual: (ID) sender; Add to

... AppDelegate.m

  - (IBAction) openFile Manually: (ID) sender; {NSOpenPanel * openPanel = [NSOpenPanel OpenPenel]; NSArray * fileTypes = [Object with NSArray array: @ "xml", zero]; NSInteger result = [openPanel runModalForDirectory: NSHomeDirectory () file: zero type: fileTypes]; If (Results == NSOKButton) {[Process file: [openPanel filename]]; }} - (BOOL) Application: (NSApplication *) The application openfile: (NSString *) file name {return [auto-process file: filename]; } - (BOOL) Process file: (NSString *) file {NSLog (@ "The following file has been deleted or chosen:% @", file); // return the process file here; // Return yes, when the file is successfully processed, and no one returns. }    

Comments