nsurlsession

iOS 7 NSURLSession Download multiple files in Background

大城市里の小女人 提交于 2019-12-03 10:05:09
问题 I want to download a List of files using NSUrlSession. I have a variable for counting the successful downloads @property (nonatomic) int downloadsSuccessfulCounter; . While the files are being downloaded I disable the Download Button . When the counter is equal to the download list size, I enable the button again and set the counter to 0. I do this in the method: -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *

NSURLSessionDownloadTask keeps retrying when using Background Configuration

我只是一个虾纸丫 提交于 2019-12-03 09:53:23
问题 I have a problem when it comes to a slow backend and downloading data with background configuration. NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:identifier]; _backgroundSession = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil]; NSURLSessionDownloadTask *downloadTask = [_backgroundSession downloadTaskWithURL:URL]; [downloadTask resume]; If the connection is astablished but it takes more than 60

HTTP Long Polling in Swift

做~自己de王妃 提交于 2019-12-03 09:16:48
I am trying to implement a long-polling solution in Swift using iOS 8+. While the solution undoubtedly works and leaves the main thread free for UI interactions, the memory usage climbs continuously so I am obviously doing something wrong. The class I have written is as follows: enum LongPollError:ErrorType{ case IncorrectlyFormattedUrl case HttpError } public class LongPollingRequest: NSObject { var GlobalUserInitiatedQueue: dispatch_queue_t { return dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0) } var GlobalBackgroundQueue: dispatch_queue_t { return dispatch_get_global

NSURLSession delegate methods not called

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have created a very simple app to download a text file from my web server. I have this working perfectly with NSURLConnection, but am trying to migrate over to NSURLSession instead. The issue I am having is that none of the delegate methods are being called. My server is password protected so I need to use the basic http authentication to access the file, but when the didReceiveChallenge method is never called. The line of code [getFileTask resume] seems to have no effect on anything. My setup is as follows: @interface ViewController :

NSURLSession dataTaskForRequest:completion: unrecognized selector sent to instance

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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: You have to init URLSession with a configuration:

When does NSURLSession run?

给你一囗甜甜゛ 提交于 2019-12-03 08:29:55
I have a situation in which when the device receives a push notification, I would send a NSURLSession combined with a NSURLConnection . I have a couple of questions regarding NSURLSession . Does NSURLSession's Data Task automatically resume in the background, if internet connection is lost? Does NSURLSession automatically attempt to complete the task if there is no internet initially, or does the session just return with an error? Looks like it's down to you to handle the retry. When any task completes, the NSURLSession object calls the delegate’s URLSession:task:didCompleteWithError: method

HTTP Request in swift not working

ε祈祈猫儿з 提交于 2019-12-03 08:17:38
问题 I'm trying to learn about working with APIs in Swift. As a good first test, I figured I'd hit the itunes API and just return some search results. I'm in playground using the following code. I don't get any errors, but my println isn't outputting anything. Anyone know what's wrong? Thanks! import UIKit import XCPlayground XCPSetExecutionShouldContinueIndefinitely() let url = NSURL(string: "https://itunes.apple.com/lookup?id=909253") let task = NSURLSession.sharedSession().dataTaskWithURL(url!)

How to resume NSURLSession download process after app force-quit and app relaunch?

久未见 提交于 2019-12-03 08:06:16
问题 I have implemented NSURLSession for downloading fairly large files from our servers. Now as long as I'm working in foreground or background and go back to the app the transactions are working and getting finished. But if I force-quit the app using the the multitasking screen and re-open the app again. the downloading process is not getting finished although as I understood from the docs, it should, here what the docs state: If an iOS app is terminated by the system and relaunched, the app can

AFNetworking Background Session Configuration for iOS 8 Extension

Deadly 提交于 2019-12-03 07:28:13
I'm currently developing an iOS 8 App Extension, and am having difficulty with this one last piece. In the rest of my app, I use an AFHTTPSessionManager subclass that I instantiate like this: + (MYAPIClient *)sharedClient { static MYAPIClient *_sharedClient = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _sharedClient = [[MYAPIClient alloc] initWithBaseURL:[NSURL URLWithString:kMYBaseURL]]; _sharedClient.requestSerializer = [[MYAPIRequestSerializer alloc] init]; _sharedClient.responseSerializer = [[MYAPIResponseSerializer alloc] init]; }); return _sharedClient; } When I

Creating a non-tracking in-app web browser

南楼画角 提交于 2019-12-03 07:09:41
I am trying to create a webview (as an exercise) that does not track or store any browsing history locally. I have made it so that when the webview is closed, it calls the following [[NSURLSession sharedSession]resetWithCompletionHandler:^{}]; but I am finding that things like google search history persists some how between sessions. I have also tried clearing cookies separately through NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (NSHTTPCookie *cookie in [storage cookies]) { [storage deleteCookie:cookie]; } [[NSUserDefaults standardUserDefaults]