How to Enable iOS Share Extension to Post Photos Faster?

0
Shares
How to Enable iOS Share Extension to Post Photos Faster?
2 (40%) 4 votes

 

In 2015, Apple introduced an iOS Share Extension in iOS 8. It allows users to share photos and videos on a server from iOS photos (gallery/library) app.

This share extension also allows users to share content with other entities like on social media sites. Previously, if any users want to share the content, they have to copy the content and then open an app in which they want to share and then perform an action.

However, by having a feature like a share extension in an iPhone app, users can directly share the photo content, wherever they want.

Apps Like Facebook, Twitter, and Instagram Enabled iOS Share Extension Feature in their App to Upload Photos Faster

Users might have observed Instagram’s recent update, which is about of share extension. After this Instagram’s update, users update their post from other iOS apps without opening it. Even, they can send pictures directly to their feeds from photo editing applications.

Share extension had become available for developers since 2014 and many apps like Facebook and Twitter already have the share option. However, Instagram takes the decision to add this feature after two years, it clearly indicates that Instagram realized the importance of user engagement and enhancement and thus, added Share Extension into its app.

This is not limited to system applications. In fact, any custom application that presents an instance of the UIActivityViewController class will see the share extension. The file type is also managed by the Share Extension.

Adding any iOS application in UIActivityViewController can show the application icon where Facebook, WhatsApp, Mail, and Twitter, is displayed while sharing any document. By clicking on the application icon, we can open an application and customized view, based on the requirements.

Objective

To enable iOS Share Extension in Swift app to share and post photos faster than before.

Where to Use Share Extension Feature?

You can use share extension feature for many things like Photos, Videos, Text File, Music File, PDF File, and Web Page, as it could not be created separately.

Step 1–

To create an iOS app, you have to first go to File>> New>> Project and select ‘Single View Application’.

Step 2–

To create “Share Extension”, you have to go to File>>New>>Target. You will see an iOS section application is selected by default.

Now, select “Share Extension” and click on “Next” button. Enter the product name (ex: ExtentionInApp) and click on “Finish” button.

It will populate an alert in Xcode for Activate extension, then click on “Activate” button.

Enabled iOS Share Extension

 

iOS Share Extension to Post Photos Faster

 

create “Share Extension”

Step 3 – Enable App Group

Now, refer link to manage group and bundle ID: http://bit.ly/27K0aOM. Select project “Target” and go to “Capabilities” option.

Turn “App Group” ON.

Now, select “Extension” (ex: ExtentionInApp) under project Target and Enable “App Group” (the same process we have done with App “Target”>> “Capabilities”)

Share extension is added to your project successfully.

Now, Let’s discuss how to work with “Share Extension”?

Once you have created Share Extension, you will see some files and classes added to the projects.

 

Enable App Group

Step-1

By Default, it adds “ShareViewController.h” and “ShareViewController.m” Class.

There are 3 predefined methods already integrated in “ShareViewController.m”, which are:

  1.     didSelectPost:- This method will call when user selects post and upload contentText and/or NSExtensionContext attachment.
  2.    configurationItems: It returns array of SLComposeSheetConfigurationItem.
  3.     isContentValid: This method validates contentText and/or NSExtensionContext attachments.

Step 2-

“MainInterface.storyboard” to add UI interface.

Step 3-

Info.plist that have added “NSExtension”

add iOS share extension in iOS

Here is the Code to get Photos/Videos data from Extension class to mention in “ViewDidLoad” of “ShareViewController.m”

for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
// Here kUTTypeAppleProtectedMPEG4Video is one kind of video type you can modified base on your requirement.
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeAppleProtectedMPEG4Video]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeAppleProtectedMPEG4Video options:nil completionHandler:^(NSData *video, NSError *error)
{
// You will get Video data here that you can submit to server.
if(video) {
}
}];
}
// Here kUTTypeImage is one kind of photo type you can modified base on your requirement.
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(NSData *image, NSError *error) {
// You will get Image data here that you can submit to server.
if(image) {
}
}];
}
}
}

Let’s start working around

1. Run the app that has added UIActivityViewController

2. Select an image/video to share to open a UIActivityViewController. You can see your app in it.

 

Technical Post Image from the Best iOS App Development Company

  1. In case, you are not able to see your app in UIActivityViewController, then click on ‘more button’ to open Activities screen. In that screen, you can ON switch in front of app name to see your app in UIActivityViewController from next time.

5

Conclusion

Now, you know how to enable iOS share extension in your next app to share photos faster than before, right? If you’ve any questions regarding this article or source code, you can comment down below. We answer your questions as soon as possible.In fact, we have 44 experienced iOS developers here at our iPhone app development center. Feel free to ask any questions related to iOS development, or to validate and to get estimate app development hours for your app idea.

In fact, we have 44 experienced iOS developers here at our app development center. Feel free to ask any questions related to iOS development, or to validate and to get estimate app development hours for your app idea.

 
0
Shares
 

Contact us Now to Develop Photo iOS App