Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Url schemes on OS X
Qt 6.11 is out! See what's new in the release blog

Url schemes on OS X

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Archie888
    wrote on last edited by Archie888
    #1

    Hi,

    I got url schemes working on iOS; redirecting to the URL scheme address in the browser switches nicely back to the application. However, I cannot get them working on OS X. Going to the url scheme address on a browser does not bring the application to the foreground. I think I might not understand everything correctly that relates to using url schemes on OS X.

    My questions are:
    a) Should URL schemes work on a dev mode application on OS X, if you simply set the URL scheme to the info.plist inside the application package, or do you actually have to make a deployment version of the app and install it, and only then the system would recognize the scheme? My logic for this suspicion is that with the iOS build, the app is installed to the device, thus making any necessary arrangements there. I have to admit that I am not fully aware of the insides of the Apple's configuration mechanism involving the info.plist file on either OS.
    b) On iOS I am catching the URL scheme calls with the QDesktopServices::setUrlHandler function. Would it be same for the desktop? Of course I can't test this yet, as I can't get it working that the browser URL call would switch the application back to the foreground.

    What I am trying to do is to launch an external browser to authorize dropbox usage with the application, and then the flow redirects to a page that redirects using the url scheme, which should then switch the application to the foreground.

    Cheers,
    -A888

    S 1 Reply Last reply
    0
    • A Archie888

      Hi,

      I got url schemes working on iOS; redirecting to the URL scheme address in the browser switches nicely back to the application. However, I cannot get them working on OS X. Going to the url scheme address on a browser does not bring the application to the foreground. I think I might not understand everything correctly that relates to using url schemes on OS X.

      My questions are:
      a) Should URL schemes work on a dev mode application on OS X, if you simply set the URL scheme to the info.plist inside the application package, or do you actually have to make a deployment version of the app and install it, and only then the system would recognize the scheme? My logic for this suspicion is that with the iOS build, the app is installed to the device, thus making any necessary arrangements there. I have to admit that I am not fully aware of the insides of the Apple's configuration mechanism involving the info.plist file on either OS.
      b) On iOS I am catching the URL scheme calls with the QDesktopServices::setUrlHandler function. Would it be same for the desktop? Of course I can't test this yet, as I can't get it working that the browser URL call would switch the application back to the foreground.

      What I am trying to do is to launch an external browser to authorize dropbox usage with the application, and then the flow redirects to a page that redirects using the url scheme, which should then switch the application to the foreground.

      Cheers,
      -A888

      S Offline
      S Offline
      sandy.martel23
      wrote on last edited by
      #2

      @Archie888 said:

      a) Should URL schemes work on a dev mode application on OS X...

      They don't if you're using a version that has this bug:
      https://bugreports.qt.io/browse/QTBUG-34801

      Sandy.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Archie888
        wrote on last edited by Archie888
        #3

        Thanks for the input.

        It looks to me that that bug is about a situation, where the application does get focus, but there is a problem with the url in the evoking event's data.

        My current problem is that I cannot get the OS to start my application (or switch to it if it is already running, which is my normal scenario).

        I am working with Qt 5.4.

        I will have to update my current situation, however: I have now learned that one must perhaps setup the url scheming either (perhaps?) in the file [user]/Library/Preferences/com.apple.LaunchServices.plist or in the file [user]/Library/Preferences/com.apple.LaunchServices/com.apple.LaunchServices.secure.plist.

        However, trying to add my setup to either file does not seem to help.

        Here is my setup in either file:

        {
            LSHandlerPreferredVersions =     {
                LSHandlerRoleAll = "-";
            };
            LSHandlerRoleAll = "com.myappproject.myappname";
            LSHandlerURLScheme = myappname;
        }
        

        Ps., it seems that if I use the secure file, the entry is automatically erased from there for some reason.

        The info.plist in the application package has the URL scheme correct, I believe:

        ...
        <key>CFBundleURLTypes</key>
        <array>
        	<dict>
        		<key>CFBundleURLSchemes</key>
        		<array>
        			<string>myappname</string>
        		</array>
        		<key>CFBundleURLName</key>
        		<string>com.myappproject.myappname</string>
        	</dict>
        </array>
        </plist>
        ...
        

        Also, I have setup there the bundle identifier, which I believe(?) should identify the application for the launch services mechanism:

        <key>CFBundleIdentifier</key>
        <string>com.myappproject.myappname</string>
        

        As a contrast, when my redirection page is set to call webcal://, which is a url scheme for the calendar app in OS X, a pop up is launched, which asks whether it is ok to start the calendar application. With myappname:// it seems like nothing happens, so this is my current problem.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Archie888
          wrote on last edited by Archie888
          #4

          I wonder if there is something to this that I am missing here:

          "
          Launch Services Database

          Launch Services maintains a central data structure, the Launch Services database, in which it records all of the pertinent information about applications and the kinds of document files and URLs they are capable of opening. Whenever a new application becomes known to the system (such as when the user drags it from an installation disk into the Applications folder), the application is registered with Launch Services, which copies the needed information about the application into its database. Launch Services can then use this information to determine the preferred application for opening a given document file or URL.

          "
          source: developer.apple.com, Launch Services Concepts

          So there is some sort of installation that needs to be done on OS X, before url schemes can be tested? I wonder if this could be done programmatically in the dev version by editing system files.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved