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

Building a Today Extension

Building a Today Extension

Brief overview of what extensions are and the different types followed by an implementation of a Today widget

Pasan Premaratne

February 24, 2015
Tweet

More Decks by Pasan Premaratne

Other Decks in Technology

Transcript

  1. SHARED RESOURCES CONTAINER OBJ-C NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL

    *url = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.com.pasanpremaratne.TreehouseBlogReader"]; SWIFT let fileManager = NSFileManager.defaultManager() let url = fielManager.containerURLForSecurityApplicationGroupIdentifier(“group.com.pasanpremaratne.TreehouseBlogReader”)
  2. NSURLSESSION // Set up the background session configuration NSURLSessionConfiguration *config

    = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"com.companyID.myApp.backgroundSession"]; // Allow access to the shared container config.sharedContainerIdentifier = @"com.mycompany.myappgroupidentifier"; // Set up a session NSURLSession *mySession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; //Create and start a download task NSURLSessionTask *myTask = [mySession downloadTaskWithURL:someURL]; [myTask resume]; EXTENSION CODE // NSURLSessionDownloadDelegate Protocol Method - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location; // NCWidgetProviding Protocol - (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult result))completionHandler NCUpdateResult.NCUpdateResultNewData