nsurlsession

Request checksum from Amazon S3 in iOS

折月煮酒 提交于 2019-12-22 10:04:48
问题 I have developed an iOS application which can upload larger videos to an Amazon S3 server In order to do that, I have used : 1 Amazon V1 API 2 NSURLSession to upload videos to support background uploads . I have integrated a MD5 checksum to my put request to in-order to validate after file uploaded to Amazon server. NSString *md5 = [FileHash md5HashOfFileAtPath:[url path]]; NSMutableData *commandToSend= [[NSMutableData alloc] init]; unsigned char whole_byte; char byte_chars[3] = {'\0','\0','

com.apple.NSURLSession-work EXC_BAD_ACCESS Crash debugging

断了今生、忘了曾经 提交于 2019-12-22 06:48:02
问题 I'm seeing the following crash report, but it's not reproducible. How would I go about debugging it? Is this an AFNetworking issue? I'm using version 2.4.1. Crashed: com.apple.NSURLSession-work EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000000000000 Thread : Crashed: com.apple.NSURLSession-work 0 CoreFoundation 0x0000000184aad978 CFDictionaryGetValue + 56 1 Foundation 0x0000000185aa9300 _NSSetLongLongValueAndNotify + 72 2 Foundation 0x0000000185aa9300 _NSSetLongLongValueAndNotify + 72 3

Why is NSURLSession don't use my configured NSURLCache?

做~自己de王妃 提交于 2019-12-22 05:54:11
问题 iOS7 brings NSURLSession , with the help of NSURLSessionConfigure , we can customize URLCache, so i tried it, but with no luck, it seems my URLCache is not used at all. - (void)testURLCache { NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; config.requestCachePolicy = NSURLRequestUseProtocolCachePolicy; NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 100 diskCapacity:1024 * 100 diskPath:@"test.urlcache"]; NSLog(@"usage:%lu",

NSURLSessionConfiguration HTTPAdditionalHeaders not set

一曲冷凌霜 提交于 2019-12-22 05:52:51
问题 Authorization header is set in NSURLSessionConfiguration , however it is not attached to NSURLSessionDataTask . Is this a bug in Foundation framework ? NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; [configuration setHTTPAdditionalHeaders:@{@"Authorization":@"123"}]; // Initialize session with NSURLSessionConfiguration NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; NSMutableURLRequest *request = [

Resuming tasks using NSURLSession when app removed from background or on device reboot

为君一笑 提交于 2019-12-22 05:11:14
问题 I have checked many docs but could not found solution for Resuming tasks using NSURLSession when app removed from background or on device reboot. I am dealing with amazon S3 to upload some files, In that I am able to Upload file to S3 using NSURLSessionUploadTask, when app is in foreground as well as in background. Resume task when app crashed due to any other reason while uploading and if app is not removed from background. Restart task if I reboot device while uploading and if app is not

NSURLSession dataTaskForRequest:completion: unrecognized selector sent to instance

若如初见. 提交于 2019-12-22 01:46:50
问题 When trying to create my own session object NSURLSession() and request an url I get an unrecognized selector exception but when I use the shared session NSURLSession.sharedSession() everything works fine. How come? var url = NSURL(string: "http:/www.google.com") if url != nil { //throws unrecognized selector when dataTaskWithURL is called let session=NSURLSession() session.dataTaskWithURL(url!) //works let sharedSession=NSURLSession.sharedSession() sharedSession.dataTaskWithURL(url!) } 回答1:

Parsing fetched JSON to dictionary in Swift 3

只愿长相守 提交于 2019-12-21 23:12:05
问题 At some point in my app the user supplies a movie name. The controller will get more info about the movie from OMDB and store it. I run into problems getting converting the JSON from the url into a dictionary. Here's my code: @IBAction func addMovieButtonPressed(_ sender: Any) { // get title from the text field and prepare it for insertion into the url let movieTitle = movieTitleField.text!.replacingOccurrences(of: " ", with: "+") // get data for the movie the user named let movieData =

How to cancel a download request when cancel button pressed in swift

旧城冷巷雨未停 提交于 2019-12-21 23:04:47
问题 I want to cancel the download request when i press the cancel button. Now when i press download button following code works @IBAction func downloadButtonPressed(sender: UIButton) { var fileName = noticeAttacchment[0]["fileName"] as! String var fileUrl = noticeAttacchment[0]["fileUrl"] as! String if var URL = NSURL(string: fileUrl){ Api.load(URL, fileName: fileName) } } And my downloader class is class Api { class func load(URL: NSURL , fileName : String) { let sessionConfig =

How to get data from a Swift NSURLSession?

天涯浪子 提交于 2019-12-21 21:55:13
问题 For example, I have the following code: let task = NSURLSession.sharedSession().dataTaskWithURL(url, completionHandler: {data, response, error -> Void in var dann = NSString(data: data, encoding: NSUTF8StringEncoding)! self.str = dann }) task.resume() I want to transfer the data to a variable in the class (the str variable in the class). The string "self.str = dann" does not convey anything. How can I do this? 回答1: I'm not sure NSString is the type you want. JSON may be format of the data

NSURLSession: handleEventsForBackgroundURLSession method doesn't run in Background session

雨燕双飞 提交于 2019-12-21 21:16:45
问题 application:handleEventsForBackgroundURLSession:completionHandler: doesn't run when the uploads are finished in the background. When all the upload/download tasks are completed in the background then iOS should wake up the app and call the above method. But it doesn't. I have tested this by terminating the app from 'xcode stop' button and also terminated from an exception. I have followed Background Transfer consideration. I have tested this on Apple developer guide: Background example and it