views:

135

answers:

2

I've got an app:

You can drop an image file onto the app's dock icon and it will upload the image to a free image hoster. In 10.5 you could drag an image straight out of safari (and any other browser) and drop it onto the dock. (The app opened the image from the temporary folder the browser put it in and uploaded it to the net.)

Now in 10.6 the same app won't accept images dropped from safari (any other brwosers too) windows directly onto the dock icon. The browser seems to 'export' the internet-URL to image (http://somedomain.com/the%5Fimage.png) instead of the 10.5 behaviour of exporting the file name of the image-file in the cache. Local files dropped from finder are opened and handled flawlessly.

The consequences for me are: I have to implement a service that allows dropping URLs onto my dock icon. And then to decide if a local filename was dropped or a remote url. Resulting in boilerplate code to just to decide if I should open the image with [NSData dataWithContentsOfFile] or [NSData dataWithContentsOfURL] (sadly you can't create an NSURL from a local file name)

Is there a proper way to handle this and get rid of the boilerplate? (prepending a 'file://' to the filename and opening as an URL does not work.)

+3  A: 

(sadly you can't create an NSURL from a local file name)

Yes you can. Have a look at +[NSURL fileURLWithPath:] in the docs.

Peter Hosey
Better, [NSURL fileURLWithPath:path isDirectory:NO] since you know your image isn't a directory. This method does not hit the disk. +fileURLWithPath: does. This is just to see if the URL needs a trailing slash - super annoying.
Ken
A: 

thanks, for the tip. but that's not really less boiler plate than my solution :(

Jaroslaw Szpilewski