quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

NSScreencast Episode #93 Background Transfers

Background Transfers - NSScreencast

画像のダウンロードをバックグラウンドで実行

  • downloadTapped
    • if (!self.session) {
      • self.session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
    • NSURLSessionDownloadTask *task = [self.session downloadTaskWithURL:imageUrl];
    • [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    • [task resume];
  • NSURLSessionDownloadDelegate
    • didFinishDownloadingToURL
    • didWriteData
    • didResumeAtOffset
    • URLSession didCompleteWithError
  • notification
    • AppDelegate handleEventsForBackgroundURLSession
      • NSDictionary *userInfo = @{@"sessionIdentifier": identifier, @"completionHandler": completionHandler};
      • [[NSNotificationCenter defaultCenter] postNotificationName:@"BackgroundSessionUpdated"
  • vc viewWillAppear
    • [[NSNotificationCenter defaultCenter] addObserver:self
      • selector:@selector(handleBackgroundSession:)
    • handleBackgroundSession notification
      • if ([notification.userInfo[@"sessionIdentifier"] isEqualToString:self.session.configuration.identifier]) {
        • self.backgroundCompletionHandler = notification.userInfo[@"completionHandler"];
  • URLSessionDidFinishEventsForBackgroundURLSession
    • self.backgroundCompletionHandler();
    • self.backgroundCompletionHandler = nil;