1. iOS 8 Action Extension
Tech Talk Training Series
- 07/18/2014 -
Yuichi Fujiki
2. What can you do with extension?
•Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
3. What can you do with extension?
•Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
4. What can you do with extension?
•Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
5. What can you do with extension?
•Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
6. What can you do with extension?
•Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
7. What can you do with extension?
•Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
8. What can you do with extension?
•Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
9. What you can NOT do with extension
•Define custom extension point
• Provide extension by itself
• Needs to accompany with an ‘app’
10. Other things to note
• Extension runs as a separate process from containing app
• Also sandboxed
• Basically, you can consider extension is a ViewController presented from
different extension point
12. Step 1
1.Add action extension
2.Limit the extension point only to image item
• NSExtensionActivationSupportsImageWithMaxCount=1
13. Step 2
Pass image from containing app to extension
1.Present UIActivityViewController specifying the image
(“TunnelView”)
2.The initial action extension template already includes the code
to display image
NSExtensionContext
NSExtensionItem
NSExtensionItem
NSExtensionItem
NSItemProvider
self.extensionContext
inputItems attachments
14. Step 3
Receive image from Photos app
1.Create image from NSURL
•Photos app provides image via URL
15. Step 4
Add image filters to extension
1.Let’s just checkout refs/tags/step4 :))
16. Step 5
Pass edited image back to the host app
1. In Extension, package edited image into NSItemProvider and pass to Host
App
• NSExtensionContext.completeRequestReturningItems(…)
2. In Containing App, unpack passed image
• UIActivityViewController.completionItemsHandler = {
(activityType:String!, animated:Bool, items:[AnyObject]!, error:NSError!) in
…
}
17. Step 6
Save edited image to Photos app too
1.Use AssetsLibrary
•Photos framework is supposed to replace AssetsLibrary
18. Step 7
Move general use methods to framework
1.Add framework target
2.import YourFrameWork
19. Step 8
Add Safari Extension
1.Add entries in Info.plist
• NSExtentionActionvationSupportsWebURLMaxCount = 1
• NSExtensionJavaScriptPreprocessingFile = Action
• Also create “Action.js” corresponding to the entry
2. Add run method in Action.js and pass selected DOM information to extension
3. Parse the passed DOM information as plist and obtain image URL
4. Pass the edited image back to Action.js as URL
5. Implement finalize method in Action.js and replace img element with passed URL
20. Where to go from here?
• Different media (video, music, text etc)
• Different Extension Point
• Skip the view
• Choose “Request Handling” for Action Type
• Share data between your containing app and extension
• Use good-old “Open URL” approach and launch app
• Use App Group functionality