Re-targetting URL Handler in users' systems

  • I have an app in the field which handles a url.  I mean, it has one of these in its Info.plist…

        <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>myapp</string>
                </array>
                <key>LSIsAppleDefaultForScheme</key>
                <true/>
            </dict>
        </array>

    In order to fix a longstanding issue, I've now moved this entry, and the code to support it, into a helper app which is shipped in the main app's Contents/Helpers.  The idea is that the helper app now handles this URL instead of the main app.  I'm going to ship this as an update.

    It works for me, but due to past experience with the black-boxiness of Launch Services, I'm worried that users' experiences in the field will vary.  I'm not sandboxed.  So I've added some code which, upon first run of the updated app, spawns an NSTask to run lsregister, giving it the path to my app obtained from [[NSBundle mainBundle] bundlePath].  Since there are two paths to lsregister in Mac OS X history, I first try the new path, then if that does not return 0, the old path [1].  Running this command takes 80-100 milliseconds on my Core 2 Duo.

    I'm worried there will still be trouble for some users, and would appreciate any feedback, design or test suggestions.

    Thanks,

    Jerry Krinock

    [1] Here are the two commands I use:

    Using new path to lsregister:

    /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -R /path/to/MyApp.app

    Using old path to lsregister:

    /System/Library/Frameworks/ApplicationServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -R /path/to/MyApp.app

    The arguments are passed in -[NSTask setArguments:], whose documentation indicates that I "do not need to do special quoting", which I interpret to mean that I need not quote the /path/to/MyApp.app.

    The option "-R" means "Recursive directory scan, descending into packages and invisible directories", which I presume is necessary in order to find my helper buried in Contents/Helpers.
  • Use the LSRegisterURL() function in Launch Services.

    -Jeff

    On Jul 14, 2012, at 7:20 AM, Jerry Krinock wrote:

    > I have an app in the field which handles a url.  I mean, it has one of these in its Info.plist…
    >
    > <key>CFBundleURLTypes</key>
    > <array>
    > <dict>
    > <key>CFBundleURLSchemes</key>
    > <array>
    > <string>myapp</string>
    > </array>
    > <key>LSIsAppleDefaultForScheme</key>
    > <true/>
    > </dict>
    > </array>
    >
    > In order to fix a longstanding issue, I've now moved this entry, and the code to support it, into a helper app which is shipped in the main app's Contents/Helpers.  The idea is that the helper app now handles this URL instead of the main app.  I'm going to ship this as an update.
    >
    > It works for me, but due to past experience with the black-boxiness of Launch Services, I'm worried that users' experiences in the field will vary.  I'm not sandboxed.  So I've added some code which, upon first run of the updated app, spawns an NSTask to run lsregister, giving it the path to my app obtained from [[NSBundle mainBundle] bundlePath].  Since there are two paths to lsregister in Mac OS X history, I first try the new path, then if that does not return 0, the old path [1].  Running this command takes 80-100 milliseconds on my Core 2 Duo.
    >
    > I'm worried there will still be trouble for some users, and would appreciate any feedback, design or test suggestions.
    >
    > Thanks,
    >
    > Jerry Krinock
    >
    > [1] Here are the two commands I use:
    >
    > Using new path to lsregister:
    >
    > /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -R /path/to/MyApp.app
    >
    > Using old path to lsregister:
    >
    > /System/Library/Frameworks/ApplicationServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -R /path/to/MyApp.app
    >
    > The arguments are passed in -[NSTask setArguments:], whose documentation indicates that I "do not need to do special quoting", which I interpret to mean that I need not quote the /path/to/MyApp.app.
    >
    > The option "-R" means "Recursive directory scan, descending into packages and invisible directories", which I presume is necessary in order to find my helper buried in Contents/Helpers.
  • On 2012 Jul 14, at 06:42, Jeff Johnson wrote:

    > Use the LSRegisterURL() function in Launch Services.

    Very good!  Thank you, Jeff.
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today