Re: Registering a protocol handler for an App
Re: Registering a protocol handler for an App
- Subject: Re: Registering a protocol handler for an App
- From: Dave <email@hidden>
- Date: Mon, 2 Feb 2009 11:52:56 +0000
Hi Ken,
On 31 Jan 2009, at 02:13, Ken Thomases wrote:
On Jan 30, 2009, at 10:58 AM, Dave wrote:
In order to register an Application to handle a protocol, do I
have to change anything other than add URL Types in the Plist
file? I'm having problems with my application not being opened
when a protocol request is sent with a protocol ID that my App is
registered for, e.g. it's Plist file says it should handle it.
By "protocol" I'm assuming you mean a URL scheme, right? Perhaps
you can show the XML for that part of your Info.plist.
Yes, a URL scheme, here is the XML for the whole plist file after I
added the URLTypes:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Internal Protocol GdSC</string>
<key>CFBundleURLSchemes</key>
<array>
<string>GdSC</string>
</array>
</dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array/>
<key>CFBundleTypeIconFile</key>
<string>ShowcaseDoc.icns</string>
<key>CFBundleTypeName</key>
<string>Showcase Dev Files</string>
<key>CFBundleTypeOSTypes</key>
<array/>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>Showcase Dev</string>
<key>CFBundleIdentifier</key>
<string>com.genx.showcase</string>
<key>CFBundleGetInfoString</key>
<string>Get Info Version 1.0.0.0198</string>
<key>CFBundleIconFile</key>
<string>Showcase.icns</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>Version 1.0.0.0198</string>
<key>CFBundleName</key>
<string>Showcase Dev</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0.0198</string>
<key>CFBundleSignature</key>
<string>GdSC</string>
<key>CFBundleVersion</key>
<string>2.8.1.472</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>LFPrefersCarbon</key>
<true/>
<key>LSGetAppDiedEvents</key>
<true/>
<key>NSAppleScriptEnabled</key>
<string>YES</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2008 - All Rights Reverved.</string>
</dict>
</plist>
Do have to change anything else?
Well, Launch Services should launch your app without you having to
do anything else, but your app won't do anything unless you
register a handler for the 'GURL' (get URL) Apple Event.
Launch services doesn't seem to get called, or at least it doesn't
load the app. The application already handling GURLs ok, so the
handler should be called. My code is in a plugin and I can get it to
work when I map it manually using the "More Internet" System Prefs
Panel. There are a number of plug-in type app that get passed the URL
from a sort of Framework the way I have set it up is that I use the
CreatorCode of the as the Protocol (I think I will change it so it's
always prefixed with a constant, e.g.XXXXGdSc, XXXXGxSC, XXXXGxTT
etc. (these get mapped to all lowercase)). But for now I think I have
got it working ok, I'm not sure if it was the "More Internet" panel
or if I needed to copy the application as you suggested, but when I
tried it with a different "Prootcol" code, e.g. "GxXX" it worked ok.
http://developer.apple.com/documentation/Cocoa/Conceptual/
ScriptableCocoaApplications/SApps_handle_AEs/chapter_11_section_4.html
Do I have to do something special at install or run time?
No. During development it's sometimes the case that the Finder or
Launch Services doesn't realize that your app's capabilities have
changed. The new Info.plist isn't rescanned to update the system
caches. If you duplicate your app in the Finder, does the new copy
get opened for the URL scheme?
Lastly, are you sure there isn't some other application that claims
the same scheme? If there is, it's up to the system to decide
which to use for a given scheme, unless the user has specified a
preference.
There is no central system-provided GUI for the user to specify
their preference for handlers for URL schemes. Safari's
preferences let you specify the preferred handler for http: and
Mail's for mailto:. You can implement a similar interface using
LSSetDefaultHandlerForURLScheme, but you should only do so in
response to the user expressing their preference. It's bad form to
"steal" that preference from the user.
These are just private protocol keys between our server and the
application. We have picked some obscure names for the "protocol"
handlers we are using, but I'm not sure how to prevent a conflict
with other applications. I have used the Creator Code of the
application as a key, I could use the Creator ID with the dots
deleted instead, e.g. comshowcasegenx. What do you think? At the
moment I have chosen 4 character constant followed by the
Application's Creator Code.
Thanks for you help
All the Best
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden