Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS Extension

iOS Extension

Cocoaheads Taipei 11/13

Pin-Shih Wang

November 14, 2014
Tweet

More Decks by Pin-Shih Wang

Other Decks in Programming

Transcript

  1. App

  2. See scores from your favorite team Home Find App Wait

    App Open wait for loading Auto upload Rate me Cache Sync 8:1
  3. Host app • An app that a user employs to

    choose an app extension is called a host app Host
 app Today.app Today Chrome.app Share/Action Dropbox.app Document Provider Photo.app Photo Editing
  4. • an app that contains one or more extensions is

    called a containing app Containing app Containing
 app extension extension extension
  5. • an app that contains one or more extensions is

    called a containing app Containing app
  6. App extension • an app extension lets you extend custom

    functionality and content beyond App
 extension
  7. Extension Type Host App host app use Today Today.app NotificationCenter.framework

    Share any app UIActivityViewController Action any app UIActivityViewController Photo Editing Photo.app PhotosUI.framework
 Photos.framework Document Provider any app UIDocumentPickerViewController Custom Keyboard any app Host
 app
  8. Extension Type Enter point Today UIViewController <NCWidgetProviding> Share SLComposeServiceViewController Action

    SLComposeServiceViewController UI and non-UI variants Photo Editing UIViewController <PHContentEditingController> Document Provider UIDocumentPickerViewController UI and non-UI variants Custom Keyboard UIInputViewController App
 extension
  9. App
 extension Containing
 app Pocket AddToPocket Different process • Isolated

    address space • Executes independently • System optimizes separately Run Separately
  10. Share Resource NSUserDefaults *shared = [[NSUserDefaults alloc] initWithSuiteName:@“group.domain"]; NSURL *directory

    = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.domain"];
  11. App
 extension Containing
 app Pocket AddToPocket Server Server • Same

    data model • Same logic • Same views Share Code
  12. Share Code NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.domain"]; NSString *sorPath

    = [NSString stringWithFormat:@"%@/Dylib.framework",[[NSBundle mainBundle] bundlePath]]; NSString *desPath = [NSString stringWithFormat:@“%@/Library/Caches/ Dylib.framework",containerURL.path]; BOOL copyResult = [[NSFileManager defaultManager] copyItemAtPath: sorPath toPath:desPath error:&err];
  13. • Containing app is still most important • Extension cannot

    without containing app • Don't have full use of system resources • Make it seamless • Make it useful
  14. App Extension • Create an app extension by adding a

    new target to an app • Add necessary libraries to extension target • ViewController
  15. viewController’s life cycle • initWithCoder: • viewDidLoad • widgetMarginInsetsForProposedMarginInsets: •

    widgetPerformUpdateWithCompletionHandler: • viewWillAppear: • viewDidAppear:
  16. Some APIs are Unavailable to App Extensions • Access a

    sharedApplication object • Use any API marked in header files with the NS_EXTENSION_UNAVAILABLE macro, or similar unavailability macro, or any API in an unavailable framework • Access the camera or microphone on an iOS device • Perform long-running background tasks • The specifics of this limitation vary by platform, as described in the extension point chapters in this document. • (An app extension can initiate uploads or downloads using an NSURLSession object, with results of those operations reported to the containing app.) • Receive data using AirDrop • (An app extension can send data using AirDrop in the same way an app does: by employing the UIActivityViewController class.)
  17. App Store • NOTE ABOUT 64-BIT ARCHITECTURE • An app

    extension target must include the arm64 (iOS) or x86_64 architecture (OS X) in its Architectures build settings or it will be rejected by the App Store. Xcode includes the appropriate 64-bit architecture with its “Standard architectures” setting when you create a new app extension target. • If your containing app target links to an embedded framework, the app must also include 64-bit architecture or it will be rejected by the App Store.
  18. End