iOS 8 Action Extension Training

20
iOS 8 Action Extension Tech Talk Training Series - 07/18/2014 - Yuichi Fujiki

description

Training session slides for internal training about iOS8 extension.

Transcript of iOS 8 Action Extension Training

Page 1: iOS 8 Action Extension Training

iOS 8 Action ExtensionTech Talk Training Series

- 07/18/2014 -

Yuichi Fujiki

Page 2: iOS 8 Action Extension Training

What can you do with extension?• Provide a program for other apps to use

• Today

• Action

• Share

• Photo Editing

• Document Provider

• Custom Keyboard

Page 3: iOS 8 Action Extension Training

What can you do with extension?• Provide a program for other apps to use

• Today

• Action

• Share

• Photo Editing

• Document Provider

• Custom Keyboard

Page 4: iOS 8 Action Extension Training

What can you do with extension?• Provide a program for other apps to use

• Today

• Action

• Share

• Photo Editing

• Document Provider

• Custom Keyboard

Page 5: iOS 8 Action Extension Training

What can you do with extension?• Provide a program for other apps to use

• Today

• Action

• Share

• Photo Editing

• Document Provider

• Custom Keyboard

Page 6: iOS 8 Action Extension Training

What can you do with extension?• Provide a program for other apps to use

• Today

• Action

• Share

• Photo Editing

• Document Provider

• Custom Keyboard

Page 7: iOS 8 Action Extension Training

What can you do with extension?• Provide a program for other apps to use

• Today

• Action

• Share

• Photo Editing

• Document Provider

• Custom Keyboard

Page 8: iOS 8 Action Extension Training

What can you do with extension?• Provide a program for other apps to use

• Today

• Action

• Share

• Photo Editing

• Document Provider

• Custom Keyboard

Page 9: iOS 8 Action Extension Training

What you can NOT do with extension• Define custom extension point

• Provide extension by itself

• Needs to accompany with an ‘app’

Page 10: iOS 8 Action Extension Training

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

Page 11: iOS 8 Action Extension Training

Step 01.Clone https://github.com/yfujiki/MyPhotoFilter.git

2.% git checkout refs/tags/step0

Page 12: iOS 8 Action Extension Training

Step 11.Add action extension

2.Limit the extension point only to image item

• NSExtensionActivationSupportsImageWithMaxCount=1

Page 13: iOS 8 Action Extension Training

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

Page 14: iOS 8 Action Extension Training

Step 3Receive image from Photos app

1.Create image from NSURL

•Photos app provides image via URL

Page 15: iOS 8 Action Extension Training

Step 4Add image filters to extension

1.Let’s just checkout refs/tags/step4 :))

Page 16: iOS 8 Action Extension Training

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 … }

Page 17: iOS 8 Action Extension Training

Step 6Save edited image to Photos app too

1.Use AssetsLibrary

•Photos framework is supposed to replace AssetsLibrary

Page 18: iOS 8 Action Extension Training

Step 7Move general use methods to framework

1.Add framework target

2.import YourFrameWork

Page 19: iOS 8 Action Extension Training

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

Page 20: iOS 8 Action Extension Training

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