Here I am going to explain the different steps of implementing the Share Extension in iOS with swift language. Before going to the implementation part,  we should know what share extension is and what its purpose is. Share Extension first came into light from “iOS 8.0”, which is used to share the content from the device on the app. These content are basically image, text, video etc.

According to Apple, “Share extensions give users a convenient way to share content with other entities, such as social sharing websites or upload services“. This feature gives a user to post the content easily on the app, they just have to click on the share button and select the app from the sharing area, that open the System generate UI.

Implementation of Share Extension with Steps

Step1=> Basically, share extension is not a stand-alone application. So, first, we have to create a project called “Share Extension Demo”. Make UI which looks in the following way:-

Step2 => Now we have to add the share extension into our project. For adding share extension, Go to File > New > Target, create the share Extension file called ShareExt.

Step3 =>  For sharing data between extension and host-app we need to setup App-Groups in capabilities section. Open Share Extension Demo target > Capabilities. Enable App groups and select group.YOUR_BUNDLE_ID. 

Step4=> Add the same in shareExt, as shown in the image below:-

Step5=> Now configuration of the share extension is almost done. From your project, you will see a Share Extension folder, which consists of shareViewController that inherits the SLComposeViewController.

In this project, we share the image from the photos app and show into the Main app. To achieve this, we use UserDefault to save the image data.

Step=>6  Now, In View Controller class we try to access the shared image from user default.

Great, we completed all the steps to integrate the share extension in our app. Now, Select the ShareExt and run the project. You will get the following screen:-

After selecting the photos, which will redirect you to the native photos application of iOS, select any image and click on the share button below, then you will see that your app exists there.

Hey, Now you have to run your main app i.e. ShareExtensionDemo. After successfully run, stop the application and follow these steps:-

  • Go to the gallery into your iPhone.
  • Select an image.
  • Click on the share button.
  • Select your app to share.
  • After Share, the image opens your app.

Note:- You have to create the certificate and provisioning for both ShareExt and ShareExtensionDemo on Apple Developer Account.

Hurray, You have successfully implemented the Share Extension to your app. If you have any queries, then please ask in the comment. 

Thank you, Good Day ?