7 Replies Latest reply on Oct 24, 2016 10:39 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.

              • 4. Re: iOS app extensions
                ralphs26798824 Level 1

                martinb77004568 How'd you get on with this? Any progress?

                 

                I have successfully added the file types and can 'open with' when selecting a file in, for instance, an email however the 'share to' from Safari does not seem to be working on any page or file types. Did you manage to get this working without an App Extension?

                 

                Cheers,

                • 5. Re: iOS app extensions
                  martinb77004568 Level 1

                  Unfortunately, I didn't manage to get it working at all. I still hope someone will find a solution some day. This is a pretty essential part of an app...

                   

                  Btw: How did you manage to get the files show in the "open with" dialog? In the same way as described above (by extending the plist file) or did you do something else?

                  • 6. Re: iOS app extensions
                    ralphs26798824 Level 1

                    From what I have found it is possible but not as easy as associating file types. Apparently the 'Open with' and 'Share to' are two different things and for the latter to work, you need to create an App Extension:

                    App Extension Programming Guide: Creating an App Extension

                     

                    This guy lists how he has managed to get this working with Phonegap / Cordova but not with PGB:

                    iphone - Cordova: sharing browser URL to my iOS app (Clipper ios share extension) - Stack Overflow

                     

                    I plan to look more into this but do not have time at present.

                     

                    For the former, yes, I have managed to associate file types and even custom files by modifying the plist through the Config.xml. For example this (you need all of it) would register my app against any '*.dino' file which the user selects from an email etc;

                    <gap:config-file platform="ios" parent="UTExportedTypeDeclarations">

                            <array>

                                <dict>

                                    <key>UTTypeConformsTo</key>

                                    <array>

                                        <string>public.data</string>

                                    </array>

                                    <key>UTTypeDescription</key>

                                    <string>Dinosaur Definition File</string>

                                    <key>UTTypeIdentifier</key>

                                    <string>com.dinosaur.def</string>

                                    <key>UTTypeTagSpecification</key>

                                    <dict>

                                        <key>public.filename-extension</key>

                                        <string>dino</string>

                                    </dict>

                                </dict>

                            </array>

                    </gap:config-file>

                    <gap:config-file platform="ios" parent="CFBundleDocumentTypes">

                         <dict>

                                    <key>CFBundleTypeName</key>

                                    <string>Dinosaur Definition File</string>

                                    <key>LSHandlerRank</key>

                                    <string>Owner</string>

                                    <key>CFBundleTypeRole</key>

                                    <string>Editor</string>

                                    <key>LSItemContentTypes</key>

                                    <array>

                                        <string>public.dino</string>

                                        <string>com.dinosaur.def</string>

                                    </array>

                                </dict>

                    </gap:config-file>

                     

                    I am not 100% sure this perfect but it work..

                     

                    Good luck!

                     

                    Ralph

                    • 7. Re: iOS app extensions
                      martinb77004568 Level 1

                      Thanks for your reply. I thought the same: It seems like you need to create an app extension if you want to display it in Safari as well. It would be really nice if, some day, this was possible on PGB as well...