nsurlsessiondownloadtask

Download a file with NSURLSession in Swift

我的梦境 提交于 2019-11-30 23:12:12
i have like 2 problems here , first i cant set NSURLSessionDownloadDelegate with a swift project, compiler says Type 'ViewController' does not conform to protocol 'NSURLSessionDownloadDelegate' Second problem is i cant find NSURLSession methods to download a simple file here is the way i use to download the simple file var url:NSURL = NSURL.URLWithString(fileURL) var request:NSURLRequest = NSURLRequest(URL: url) var downloadTask:NSURLSessionDownloadTask = sessionManager.downloadTaskWithRequest(request) downloadTask.resume() and these are the methods i want to make in swift URLSession:

Download a file with NSURLSession in Swift

老子叫甜甜 提交于 2019-11-30 18:12:38
问题 i have like 2 problems here , first i cant set NSURLSessionDownloadDelegate with a swift project, compiler says Type 'ViewController' does not conform to protocol 'NSURLSessionDownloadDelegate' Second problem is i cant find NSURLSession methods to download a simple file here is the way i use to download the simple file var url:NSURL = NSURL.URLWithString(fileURL) var request:NSURLRequest = NSURLRequest(URL: url) var downloadTask:NSURLSessionDownloadTask = sessionManager

URLSessionDidFinishEventsForBackgroundURLSession Not Calling- Objective-C

本小妞迷上赌 提交于 2019-11-30 13:41:21
NSURLSession Delegate method URLSessionDidFinishEventsForBackgroundURLSession is not Calling ? I already enabled the Background Modes in project capabilities settings. Here is the code AppDelegate.h Method @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (nonatomic, copy) void(^backgroundTransferCompletionHandler)(); @end AppDelegate.m Method -(void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler{ self

Get the data from NSURLSession DownloadTaskWithRequest from completion handler

爱⌒轻易说出口 提交于 2019-11-30 13:04:04
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)" request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding) let task = NSURLSession

NSURLSession with invalid resume data

放肆的年华 提交于 2019-11-30 09:58:32
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 the NSURLSessionResumeInfoLocalPath , which is "/private/var/mobile/Containers/Data/Application

Does NSUrlSession continue file transfer if the app is killed from task manager?

断了今生、忘了曾经 提交于 2019-11-30 09:21:02
I have tried various samples from the web (the last one being this one ) in order to get a better understanding of NSUrlSession . What I was hoping to see: file downloads will continue even if the app that triggered them gets killed (for instance by the user through the task manager). However this does not seem to happen. Is this a configuration issue or does background file transfer not work if the app gets terminated? I thought the whole idea was that iOS will restart the app. If the system kills your app and your background session has active downloads, your downloads will continue and the

How can I check that an NSData blob is valid as resumeData for an NSURLSessionDownloadTask?

為{幸葍}努か 提交于 2019-11-29 22:40:22
I have an app that's using background downloads with the new NSURLSession APIs. When a download cancels or fails in such a way that NSURLSessionDownloadTaskResumeData is provided, I store the data blob so that it can be resumed later. A very small amount of the time I am noticing a crash in the wild: Fatal Exception: NSInvalidArgumentException Invalid resume data for background download. Background downloads must use http or https and must download to an accessible file. The error occurs here, where resumeData is the NSData blob and session is an instance of NSURLSession : if (resumeData) {

URLSessionDidFinishEventsForBackgroundURLSession Not Calling- Objective-C

怎甘沉沦 提交于 2019-11-29 19:05:18
问题 NSURLSession Delegate method URLSessionDidFinishEventsForBackgroundURLSession is not Calling ? I already enabled the Background Modes in project capabilities settings. Here is the code AppDelegate.h Method @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (nonatomic, copy) void(^backgroundTransferCompletionHandler)(); @end AppDelegate.m Method -(void)application:(UIApplication *)application

Does NSUrlSession continue file transfer if the app is killed from task manager?

人走茶凉 提交于 2019-11-29 14:46:32
问题 I have tried various samples from the web (the last one being this one) in order to get a better understanding of NSUrlSession . What I was hoping to see: file downloads will continue even if the app that triggered them gets killed (for instance by the user through the task manager). However this does not seem to happen. Is this a configuration issue or does background file transfer not work if the app gets terminated? I thought the whole idea was that iOS will restart the app. 回答1: If the

Weird NSURLSessionDownloadTask behavior over cellular (not wifi)

假装没事ソ 提交于 2019-11-28 23:02:52
问题 I've enabled Background Modes with remote-notification tasks to download a small file (100kb) in background when the app receives a push notification. I've configured the download Session using NSURLSessionConfiguration *backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfiguration:sessionIdentifier]; [backgroundConfiguration setAllowsCellularAccess:YES]; self.backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfiguration delegate:self delegateQueue: