3 Replies Latest reply on Aug 4, 2016 2:38 AM by martinb77004568

    iOS app extensions

    martinb77004568 Level 1

      Hi,

       

      I am currently developing an iOS app using PGB. What I want to achieve: When a user clicks on a share button somewhere (outside the application), you see a menu looking like this:

      rDxga.png

      I need to show my application in this menu so that users are able to share things to my app. Please note that I am not talking about sharing content from inside my app to another one (which can be achieved using GitHub - EddyVerbruggen/SocialSharing-PhoneGap-Plugin: Cordova plugin to share text, a file (image/PDF/..), or a URL (or…  ). I want that, if a user clicks on the share button in safari, my application is visible in the menu that pops up.

       

      For Android, this can be achieved using the cordova-webintent plugin. But how can I make this work on iOS?

      I already found a tutorial. But I assume this won't work since he explains that we have to create files in XCode: iphone - Cordova: sharing browser URL to my iOS app (Clipper ios share extension) - Stack Overflow

       

      Is there maybe a plugin I haven't found yet? Or something built into PGB I can use? Today, you can share things to nearly every popular application. So, I think/hope I just haven't found the right plugin yet. It would be really nice if you could help me!

        • 1. Re: iOS app extensions
          ryanskihead Adobe Employee

          I believe this is called a "Share Extension", and unfortunately at the moment from some quick searching, I don't think this has been plugin-ized in cordova yet. I'm guessing it involves configurations that simply aren't supported by the plugin infrastructure yet (but not positive).

           

          If that's true then your solution would be to use PhoneGap locally on OSX and utilize XCode for a Share Extension.

           

          Edit: might be possible, see reply below.

          • 2. Re: iOS app extensions
            ryanskihead Adobe Employee

            Cancel that, this might be possible. Have a look at this post: cordova - Share something to a phonegap app - Stack Overflow (down below you'll see "Edit : there are a few people asking how to do this on iOS").

             

            1. Associate your app with the right file type associations by adding the relevant information in your info.plist. This SO answer explains how to do it : How do I associate file types with an iPhone application?. This will make your app appear in the list but your app won't receive the data yet.
            2. Your application will now be launched with new parameters. You now have to be able to read these parameters. Check this question/answer on SO, it does exactly that : How to pass arguments to app built on Phonegap

            For the first part you'd need to modify your app's plist -- on Build this is done with config-file elements: Modifying Manifests | PhoneGap Docs

             

            For the second part, you might need to use a custom url scheme plugin to handle the launch arguments: GitHub - EddyVerbruggen/Custom-URL-scheme: Launch your Cordova/PhoneGap app by a Custom URL scheme like mycoolapp://

             

            You'll need to do some experimentation here, not sure about all the details.

            • 3. Re: iOS app extensions
              martinb77004568 Level 1

              First of all, thank you for your detailed answer. Now I know where to start and that it is possible.

               

               

              I tried associating jpeg files with my application. For some reason, my app still isn't displayed in the share menu. (Tested in the Photos application and a .jpg image in Safari)

              Am I missing something? This is what I added to my config.xml:

               

              <gap:config-file platform="ios" parent="CFBundleDocumentTypes" mode="replace">
                      <array>
                          <dict>
                              <key>CFBundleTypeName</key>
                              <string>JPG</string>
                              <key>CFBundleTypeRole</key>
                              <string>Viewer</string>
                              <key>LSHandlerRank</key>
                              <string>Alternate</string>
                              <key>LSItemContentTypes</key>
                              <array>
                                  <string>public.jpeg</string>                    
                              </array>
                          </dict>
                      </array>
                  </gap:config-file>
              

               

              I also tried replacing the CFBundleTypeName "JPG" with "public.jpeg" but that didn't work either.

               

              I unpacked the .ipa file and converted the plist file to .xml. Here, I can see my entries listed as expected:

              <key>CFBundleDisplayName</key>
                  <string>Test-App</string>
                  <key>CFBundleDocumentTypes</key>
                  <array>
                      <dict>
                          <key>CFBundleTypeName</key>
                          <string>public.jpeg</string>
                          <key>CFBundleTypeRole</key>
                          <string>Viewer</string>
                          <key>LSHandlerRank</key>
                          <string>Alternate</string>
                          <key>LSItemContentTypes</key>
                          <array>
                              <string>public.jpeg</string>
                          </array>
                      </dict>
                  </array>
                  <key>CFBundleExecutable</key>
                  <string>TestApp</string>
              

               

              According to System-Declared Uniform Type Identifiers , public.jpeg should be the correct content type. Core Foundation Keys  tells me that it is required to use  LSItemContentTypes (or similar) which I am using. So what could be the reason that my application is still not listed in the share dialog? Is it a problem with PGB or did I miss a key that is required?

              What I didn't add was the file icon (in the example from SO: Document-molecules-320.png and Document-molecules-64.png). I am not sure where to put these files (somewhere in the locales folder mabye?). But this souldn't be the reason my application isn't listed in the share dialog since I am not creating a new file type.