On 09.08.2008, at 22:53, Jacob Bandes-Storch wrote:
I want to implement a custom URL scheme (such that myscheme:whatever will open my app and somehow pass the URL as a parameter). I've been looking around for information on how to do that, and I'm getting mixed messages.

 I'm not a specialist, but I'll provide what I think is correct:

The Info.plist documentation is very clear, and I've got the keys all set up the right way such that my app opens when a URL of my custom scheme is opened. However, I'm not sure how to find out what URL was opened.

I see some implementations use -[NSAppleEventManager setEventHandler:andSelector:forEventClass:andEventID:]; with kInternetEventClass and kAEGetURL, and they implement a method (passed into the selector): - (void)handleURLEvent: (NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent.
(...)
Another thing I've seen is adding a script suite and using performDefaultImplementation and [self directParameter] to get the URL.

When a URL is opened, an Apple Event of kInternetEventClass/ kAEGetURL is sent, containing the URL. If you want to handle the URL, you'll need to catch this somehow.

Cocoa AppleScript support is fairly new (I think 10.2 or 10.3 or thereabouts). So, depending on what system version your app has as its minimal requirement, you'll either use NSAppleEventManager (which is the older class, AFAIK) or the script suite. Instead of performDefaultImplementation, I think you could also just create an NSScriptCommand or whatever the class was called. Whatever feels cleaner to you.

In other places, I see LSSetDefaultHandlerForURLScheme, and other LS* stuff.

You'll want to use the default handler thing if your scheme is likely to be shared with other apps. Like Safari, which lets you specify the application to use for handling RSS feeds, either itself or other apps, like NetNewsWire. These APIs let you explicitly set who handles a scheme. Specifying it in the Info.plist means the system decides who gets the URL, if there are several handlers. So, if this is a scheme only your app will use (i.e. x-myapp-license: or x-myapp- triggersoftwareupdate: or whatever), the Info.plist approach should be enough. Again, the different approaches may have different system requirements.

So, I need to know what the "right" way to do this is. I don't see any specific information about this in Apple's documentation.


Hope this helps a bit. If anyone knows better, please correct me. I haven't had to do that yet, that's just stuff I remember having read in places.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to