
Just as in Action Extensions, you can use a JavaScript file to get content from web pages in Safari. The entitlements file in an extension, just as in the container app, is generated when you configure App Groups. Expand the ImgurUpload group and you will see a storyboard file, an entitlements file, a view controller and a plist file under the Supporting Files group. With that set up, let’s now look at the files generated when we created the extension. Once logged in, click your username at the top right of the screen and select Settings. To get the Imgur client id, login to or register an account at /register. We use background upload because users tend to get back to the host app immediately after finishing their task in extensions, so if the upload is potentially lengthy, we want it to run to completion even when the extension is terminated. We want the extension to have access to the shared container for two reasons: first, just like the container app, every image uploaded via the extension will be saved and made available for viewing via the container app and second, we use a background session for the upload which requires the image to be saved first before uploading, so we save a temporary image in the shared container which is used in the background upload task. This will allow access to a shared container between the extension and container app. In order for an extension to share data with its container app, you need to configure an App Group. You need a developer account to enable App Groups. First, you’ll need a Client ID from Imgur to use their API and second, you’ll need to set up an App Group. There are a couple things you need to do to get it running. With the app overview out of the way, we can now set it up. To make things simple we’ll use Imgur for this as it allows users to upload images anonymously (without the images being linked to an account). We are going to build a Share extension that shares photos to a social networking site. Any custom application that presents an instance of the UIActivityViewController class will be able to see your sharing extension if you built your extension so that it can handle the file type provided by that application. This isn’t limited to system applications. With share extensions, users will now be able to share content to your service direct from within the app they are using, be it Safari, Photos or other apps. Previously, sharing content usually entailed switching from one app to another, for example, while surfing in Safari, if you wanted to share a URL, you would copy it, switch to the app you wanted to save or share it in, perform the action and then resume surfing in Safari. Share extensions, introduced in iOS 8, give users an easy and convenient way to share content with other entities, such as social sharing websites or upload services. IOS Building a Simple Share Extension in iOS 8 App
