iOS 8 Action Extension Tech Talk Training Series - 07/18/2014 - Yuichi Fujiki
Jan 15, 2015
iOS 8 Action ExtensionTech Talk Training Series
- 07/18/2014 -
Yuichi Fujiki
What can you do with extension?• Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
What can you do with extension?• Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
What can you do with extension?• Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
What can you do with extension?• Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
What can you do with extension?• Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
What can you do with extension?• Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
What can you do with extension?• Provide a program for other apps to use
• Today
• Action
• Share
• Photo Editing
• Document Provider
• Custom Keyboard
What you can NOT do with extension• Define custom extension point
• Provide extension by itself
• Needs to accompany with an ‘app’
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
Step 01.Clone https://github.com/yfujiki/MyPhotoFilter.git
2.% git checkout refs/tags/step0
Step 11.Add action extension
2.Limit the extension point only to image item
• NSExtensionActivationSupportsImageWithMaxCount=1
Step 2Pass 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
NSExtensionContextNSExtensionItem
NSExtensionItemNSExtensionItem
NSItemProvider
self.extensionContext
inputItems attachments
Step 3Receive image from Photos app
1.Create image from NSURL
•Photos app provides image via URL
Step 4Add image filters to extension
1.Let’s just checkout refs/tags/step4 :))
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 … }
Step 6Save edited image to Photos app too
1.Use AssetsLibrary
•Photos framework is supposed to replace AssetsLibrary
Step 7Move general use methods to framework
1.Add framework target
2.import YourFrameWork
Step 8Add 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
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