Member Article
Share Extensions - A Novel Feature In iOS 8
With Apple announcing its mega release of iOS 8 with over 4000 API available to developers, it has opened new doors for providing extension to the application, better known as App Extensions.
The concept of Extension has been prevalent since iOS 5. Originally, Twitter Photo, Text and location sharing extension over photoswas were a part of sharing options. Later Apple got in Facebook and Siena WeiboPhoto, Text and location sharing extension in iOS 6 and continued on to Flickr. It also included Share Sheets in iOS 6 and redesigned it in iOS 7. But, there were some or the other limitation to each, till iOS 8 came up with a new concept of Share Extensions, which are currently making waves in the mobile world.
What is Share Extension?
Share Extension is an extensibility feature from Apple that allows you to post to a sharing website or share content with others. It is now feasible to download any app from the app store, get it hook into the Share Sheets and then either share or upload your content with other groups or service.
Fundamentally, iOS 8 provides share extension in two ways:
- Basic share GUI – Here, the GUI is provided by iOS, similar to Facebook / Twitter share extension with an option to share in a selected audience.
- Custom GUI for sharing – In this option, there is a storyboard / xib to design desired custom share sheet, which can be displayed upon user action. A separate .h /.m or .swift file is created for extension.
Both these share extensions give complete freedom of posting contents to their websites. iOS 8 has also provided support for showing progress screens for the tasks which take a long time to complete.
An excellent example of share extension was featured in the keynote video at WWDC 2014, which talked about Pinterest extension in iOS. Now, Apple and Pinterest need not work out any specific implementation deal. Pinterest can just add a share extension to their app. So, when it is downloaded, the Pinterest icon and option will be right there in the Share Sheet just as built-in options.
The utility of these apps can be restricted programmatically, making it more reliable and comfortable.
How do Share Extensions Work?
Here is a creation of another project target with type extension. The code is written in its viewController.m file. There are three methods, already written which are
- isContentValid – we just validate our post.
- didSelectPost – will be called when user taps on post button on upper right side of share screen
- configurationItems – will list of all sharable items
API for posting on websites is called on didSelectPost. The extension manages session and response obtained from API and delivers it to the end user.
The App Extension Life Cycle
- User chooses app extension
- System launches app extension
- App extension code runs
- System kills app extension
After the user content gets posted on website, the system kills the extension and leaves the screen for interaction.
User session can be maintained from the application and extension can use this session for sharing various kinds of media items defined in configuration items of the extension.
An example of the above can be viewed at https://github.com/oguzbilgener/SendToInstapaper [In Swift] and https://github.com/jverdi/URLQueue [in Swift]
This was posted in Bdaily's Members' News section by SPEC INDIA .