menu
ArrowIcon
Back to Blog

Share bigger images to hybrid app using iOS Share Extension

divami

TreeImage
TreeImage

I would like to share my experience with Share Extension. The requirement is to share images to our app from external apps like Photos/Gallery, Google Drive etc.

In hybrid apps (Cordova + Ionic), we can share images from external apps to our own app. Let’s see how to implement in iOS.

In iOS, there is no direct way to share images from external apps to our app. In order to do that, we have to use “iOS Share Extension

iOS share extension gives users a convenient way to share content with other entities.

There are two ways to implement Share extension in iOS:

Approach #1: Hybrid app share extension

Integrate iOS Phonegap share extension plugin
Plugin link: https://github.com/LokeshPatel/iOS-Phonegap-app-share-extension
Reference: http://lokesh-patel.blogspot.in/2015/11/ios-phonegap-app-share-extension-images.html

When I integrated this plugin in my Hybrid app, it worked in real iPods, iPhones and all simulators (including iPhone, iPad), but it was crashing in real iPad devices. I tried to debug the app to find out the root cause and spend lot of time to find out the reason. Finally I found that the app crash is because of low memory allocated to share extension. It might even crash in real iPhones / iOS simulators when the image size is large.

iOS limits the memory for running share extensions which is lower than that of memory limits imposed on foreground apps. iOS recommends to have very limited functionality in share extension app.

Disadvantages:

  • We can not access Cordova plugins from the share extension app
  • Chances for the app to crash in real iPad devices is more even if we share 3MB image.

Approach #2: Native app share extension

It is the finest solution because iOS allocates higher memory for native app share extension compared to hybrid app share extension.With this approach, we can avoid app crashes. It works perfectly for all the images of size less than 20MB.

We have to go for iOS native share extension app. In this approach, we will get two apps.

  • Host app (Hybrid app, written in Ionic JS)
  • Share extension native app

When we install the app, both host app and share extension apps will be available. Share extension app will invoke only when the images are shared from external app (eg: iPhone Photos app, Google drive).

Conclusion:

In order to share images to our iOS app from external apps, we should follow Approach #2. Remember that even this native iOS share extension app might crash if the image size is huge.

butterfly
Let'sTalk
butterfly
Thanks for the submission.