Introduction to iOS8 extension plug-in
I. iOS8Extensions Overview
In addition to OS X v10.10 and switf, WWDC14 has become more open. When it comes to openness, of course, it is necessary to expand the number of applications (App Extension. As the name suggests, app extensions allow developers to expand app user-defined functions and content, allowing users to use this feature when using other apps, so as to achieve function and resource sharing between applications. It can be understood as a lightweight (nimble and lightweight) separation.
The following are three common plug-ins:
Target Type |
Extension point identifier |
Scenarios |
Today Extension |
Com. apple. widget-extension |
SystemNotification barDrop-down list |
Share Extension |
Com. apple. share-services |
Host App(Photo, Safari, email, voice, etc.) the first line of the sharing menu |
Action Extension (UI) |
Com. apple. ui-services |
Host App(Photo, Safari, email, voice, etc.) the second line of the sharing menu |
For [photos] In iPhone/iOS8:
For example, [] a maximum of nine (nsextensionactivationsuppsimagewithmaxcount = 9) photos can be shared with friends or to friends.
Ii. Limitations of plug-ins
The following text is excerpted from App Extension Programming Guide, which lists the limitations of the plug-in so that it is unavailable.
--------------------------------------------------------------------------------
1. Design a Streamlined UI
- An extension's UI shoshould be simple, restrained, and focused on facilitating a single task.
- To improve performance and the user's experience,AvoidIncluding extraneous UI that doesn't support your extension's main task.
2. Optimize Efficiency and Performance
(1) App extensions shoshould feel nimble andLightweightTo users.
- Design your app extension to launch quickly, aiming for wellUnder one second.
- An extension that launches too slowly is terminated by the system.
(2)Memory limitsFor running app extensions are significantly lower than the memory limits imposed on a foreground app.
- On both platforms, the system may aggressively terminate extensions because users want to return to their main goal in the host app.
- Some extensions may have lower memory limits than others.
(3) Your app extension doesn't own the main run loop, so it's crucial that you follow the established rules for good behavior in main runloops.
- For example, if your extension blocks the main runloop, it can create a bad user experience in another extension or app.
(4) Keep in mind thatGPUIs a shared resource in the system.
- App extensions do not get top priority for shared resources; for example, a Today widget that runs a graphics-intensive game might give users a bad experience. the system is likely to terminate such an extension because of memory pressure.
- Functionality that makes heavy use of system resources is appropriate for an app, not an app extension.
--------------------------------------------------------------------------------
It can be seen that the iOS system requires the simplicity of plug-ins first: Faster UI startup, less memory consumption, and shorter runloop execution time.
The restrictions on plug-ins in iOS system determine that the plug-ins to be developed must be lightweight. Sending Twitter/Weibo shares, sharing of small image files, and URL redirection is acceptable; it is not appropriate to expect rich and brilliant UIS or use them to upload large files.
Of course, you can useNSURLSessionCreate an upload/download session and initialize a background upload/download task.
Note:
Apple also limits the permissions of the extension on API usage, and the API prototype declaration disabled in the extension is markedNS_EXTENSION_UNAVAILABLEMacro. For example:
+ (UIApplication *) sharedApplicationNS_EXTENSION_UNAVAILABLE_IOS;
The restriction on sharedApplication is to prevent the plug-in from directly obtaining the UIApplication object accessing the Host application.
Iii. Plug-in working mechanism
1. The plug-in can only communicate with the Host App through context
2. The plug-in can communicate indirectly with the ining App through the shared resource zone.
3. HostApp-Extension-Containing App Workflow
- Host AppClick the plug-in icon in the system Share menu to call the extension -- Share/ActionExtension (*. appex ).
- The iOS Host App transmits the data to be shared to Share/ActionExtension through the extended context (NSExtensionContext.
- Share/Action ExtensionExtract data and serialize It To The NSUserDefaults/AppGroup Container (containerURLForSecurityApplicationGroupIdentifier) shared resource area identified by AppGroup ID.
- Share/Action Extension calls through URL SchemeContainingApp,At the same time, the plug-in sends a request completion notification to the iOS system (HostApp) through the context to return to the Host App (the iOS system will dismiss the plug-in UIViewController ).
- The Containing App reads the shared data from NSUserDefaults/containerURL using the App Group ID and processes the shared data in the future.
The extension plug-in hooks the Host App with the ining App, while the App Group Container bridges the data interaction.
Note that in iOS 8.0, only the Today Extension can be called directly.NSExtensionContextOfOpenURL: completionHandler:Open the URL link; Share/Action Extension only one Sink can be created to implement URL SchemeUIWebVewPerformLoadRequestAchieve curve saving (the so-called "Sink" refers to hiding without explicit, such as frame = CGRectZero ).
4. UI form of the plug-in
On the UIUIViewControllerThe mode exists and is displayed as a modal window by parentViewController (Host App ).
The plug-in project passesNSExtensionMainStoryboardSpecifies the UI view entry. Of course, if you do not want to use storyboard, you can also useNSExtensionPrincipalClassSpecify the name of the custom UIViewController subclass (which can also be encapsulated in UINavigationController ).
Note:
- After creating an Extension Target (Deployment Target ≥ 8.0), you must add it in Build Settings | ubuntures | Valid ubuntures.Arm64!
- When the Containing App is initially installed, the extension plug-in is not enabled. You need to go to [more] to turn on the switch.
Iv. Plug-ins and Containing App
App Group certificate Configuration
The Containing App and its Extension are shared resource zones identified by the App Group ID-App Group ContainerTo achieve data sharing.
The App ID of the Containing App and its Extension must beExplicitAnd the Extension App ID must use the Containing App ID as Prefix/Seed and be configured under the same App Group.
The App Group is configured under the com. apple. security. application-groups key in *. Entitlements file of Xcode Target | Build Settings | Code Signing entitlements.
The process of applying for a certificate and Provisioning Profile and configuring Code Signing is the same as that of a common App. For details, see the key points of iOS development certificate.
Refer:
App Extension Programming Guide/App Extension Programming Guide
App Extensions for iOS 8 in Depth
IOS8 Extensions