Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////
- //download data via NSURLSession
- ///////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////
- -(void)downloadTheData {
- [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"downloading screen data from: %@", @"beekdata.txt"]];
- NSString *myFile = [BT_strings getJsonPropertyValue:self.screenData.jsonVars nameOfProperty:@"postURL" defaultValue:@""];
- NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
- NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:nil];
- NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithURL:[NSURL URLWithString:myFile]];
- [downloadTask resume];
- }
- // Finished downloading; fire off whatever happens after...
- - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
- NSData *data = [NSData dataWithContentsOfURL:location];
- dispatch_async(dispatch_get_main_queue(), ^{
- //
- [BT_fileManager saveDataToFile:data fileName:saveAsFileName];
- NSString *dataString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
- [self parseScreenData:dataString];
- [BT_debugger showIt:self message:@"Finished Download."];
- [BT_debugger showIt:self message:[NSString stringWithFormat:@"Downloaded Info: %@: ", dataString]];
- //
- });
- }
- - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes {
- // Real Men don't pause downloads
- }
- - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite {
- // progress = percentage complete. Use the value, or don't.
- // float progress = (double)totalBytesWritten / (double)totalBytesExpectedToWrite;
- dispatch_async(dispatch_get_main_queue(), ^{
- // update any progress bars here
- });
- }
- //////////////////////////////////////////////////////////////////
- /// End of Download Methods from NSURLSession
Add Comment
Please, Sign In to add comment