nsurlsessiondownloadtask

Get the data from NSURLSession DownloadTaskWithRequest from completion handler

旧时模样 提交于 2019-12-18 15:48:25
问题 So I'm having hard time understanding something. This are the things I understand about NSURSession : Generally , I have 2 options for (as far as I know) DataTask(e.x dataTaskWithRequest) And DownloadTask(e.x DownloadTaskWithRequest ) - Using their delegate method , or use the completion handler , Can't do both. I have managed to receive DATA using dataTaskWithRequest like this : let request = NSMutableURLRequest(URL: dataSourceURL!) request.HTTPMethod = "POST" let postString = "lastid=\(id)"

Error in NSURLSessionDownloadTask

最后都变了- 提交于 2019-12-13 20:43:07
问题 I am trying to update the user's location on the backoffice even while the app is in backgound, so I trigger a location update calling the following php script: -(void)locateUserAtLocation:(CLLocation*)location{ NSDictionary* dict=[self getCurrentAppAndUrlDictionary]; NSString* app=[dict objectForKey:@"app"]; float latitude=location.coordinate.latitude; float longitude=location.coordinate.longitude; NSString* language=[[NSLocale currentLocale] localeIdentifier]; NSString* nickName=[

What is the proper use case for NSURLSessions background sessions?

不羁的心 提交于 2019-12-10 22:28:11
问题 In the comments of this answer I was having a discussion about backgroundTasks which eventually led to: Use backgroundTasks for anything that isn't related to download/upload. For upload/download use NSURLSessions's backgroundSessions. Then I made another comment asking why not use background Sessions for all types of requests and was told: For regular REST calls, background sessions are much less convenient, and generally not what you'd want. They're not a general purpose tool for every

NSURLSessionDownloadTask resumes automatically all task while in background

吃可爱长大的小学妹 提交于 2019-12-10 10:55:01
问题 I have requirement to download files in serial order. Currently I am able to do that while app is in foreground. Following is the logic I have used. Create all tasks for downloading. Resume one at a time and as the current finishes resume the next one from URLSession:task:didCompleteWithError: . This logic is working while app is in foreground but once app started to run in background(By crashing) and we again run the app before download finishes all the tasks state has been changed to resume

NSURLSession with invalid resume data

一曲冷凌霜 提交于 2019-12-08 23:35:36
问题 I use [NSURLSessionConfiguration defaultSessionConfiguration] to config my url session. I pause a task by calling cancelByProducingResumeData: to produce a resume data, and save it to the disk. When I want to restart the task, I call downloadTaskWithResumeData: . It works well until I restart the app. I kill the app after I pause a task. Then I start my app again, and call downloadTaskWithResumeData , I found that the resume data was invalid. I parse the resume data into NSDictionary and get

UNNotificationServiceExtension sometimes doesn't show image

╄→гoц情女王★ 提交于 2019-12-08 06:07:14
问题 I created subclass of UNNotificationServiceExtension to show remote attachment in notification. Randomly, attachment doesn't show. Issue is hard to reproduce, but some users reported, that after receive remote notification with image attachment, they can't see image. After some debugging, I encountered this issue once. I noticed that downloadTask() had empty location but response 's status code was 200 . override func didReceive(_ request: UNNotificationRequest, withContentHandler

How do I get the data from a finished `NSURLSessionDataTask`?

南楼画角 提交于 2019-12-07 12:22:37
问题 I know I can use dataTaskWithURL:completionHandler: to get the data in the completionHandler block, but that blocks the delegate methods from firing, and I need the didReceiveData: method to fire, as it's how I configure my progress indicator. I'm completely at a loss how to get the downloaded data once it's complete. What's the delegate method equivalent of the completion block? didCompleteWithError doesn't seem to return any NSData . I don't have to manually piece the data together in

NSURLSessionDownloadTask cancelByProducingResumeData return null

落爺英雄遲暮 提交于 2019-12-06 12:54:10
问题 I use NSURLSessionDownloadTask to download a file from server, it is run in a background session. I want to save resume data to resume the download when the app is terminated. However, the call of cancelByProducingResumeData always returns null. I cannot figure out the issue, cause I used to do a sample of resumable download task successful before. Does anybody get the same issue? 回答1: Do you know if the request satisfies the criteria outlined in the documentation for the

NSURLSessionDownloadTask resumes automatically all task while in background

荒凉一梦 提交于 2019-12-06 10:40:41
I have requirement to download files in serial order. Currently I am able to do that while app is in foreground. Following is the logic I have used. Create all tasks for downloading. Resume one at a time and as the current finishes resume the next one from URLSession:task:didCompleteWithError: . This logic is working while app is in foreground but once app started to run in background(By crashing) and we again run the app before download finishes all the tasks state has been changed to resume and all are downloading at the same time. Is this the expected behaviour or anything I am missing to

How do I get the data from a finished `NSURLSessionDataTask`?

我与影子孤独终老i 提交于 2019-12-05 13:42:38
I know I can use dataTaskWithURL:completionHandler: to get the data in the completionHandler block, but that blocks the delegate methods from firing, and I need the didReceiveData: method to fire, as it's how I configure my progress indicator. I'm completely at a loss how to get the downloaded data once it's complete. What's the delegate method equivalent of the completion block? didCompleteWithError doesn't seem to return any NSData . I don't have to manually piece the data together in didReceiveData , do I? That seems really lame when the completionHandler just hands it off to you. I wouldn