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.
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").
- 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.
- 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.
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.
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?
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?
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:
This guy lists how he has managed to get this working with Phonegap / Cordova but not with PGB:
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">
<string>Dinosaur Definition File</string>
<gap:config-file platform="ios" parent="CFBundleDocumentTypes">
<string>Dinosaur Definition File</string>
I am not 100% sure this perfect but it work..
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...