nsurlsession

get the value of variable out of closure swift

妖精的绣舞 提交于 2019-12-06 16:29:46
问题 So I have a closure called task which is a post request and I have a global variable called values and I'm trying to set the value of "values" to be the data that I retrieved back from database stored in a variable called "array". Don't worry about the tableview.reloadData part, that's already done. i just wanna know how to get the value out of closure. var values:NSArray = [] @IBOutlet weak var Open: UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() Open.target = self

Sending simple POST in Swift, getting “Empty Post” response

天大地大妈咪最大 提交于 2019-12-06 16:11:46
I have registration page in my iOS app that I'm trying to write in Swift. The first thing I'm testing out is sending a POST with the email address, this is the way I'm doing so: var bodyData = ("userEmail=%@\" \" &userPassword=%@\" \"&userDevice=%@\" \"", emailAddress.text, password.text, deviceModel) let dataToSend = (bodyData as NSString).dataUsingEncoding(NSUTF8StringEncoding) request.HTTPMethod = "POST" request.HTTPBody = dataToSend let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in if error != nil { print("error=\(error)") return } // print(

iOS: Strategies for downloading very large data from web

自古美人都是妖i 提交于 2019-12-06 13:44:05
I'm struggling with memory management in iOS while downloading relatively large files from the web (such as videos with 350MB size). The goal here is to download these kind of files and store it on CoreData on a Binary Data field. At the moment I'm using NSURLSession . dataTaskWithUrl and NSURLSession . dataTaskWithRequest methods to retrieve these files, but it looks like these methods don't treat problems such as memory usage, they just keep on filling the memory until it reaches its maximum usage, leaving me with a memory warning when I reach 380MB~. Initial Memory Usage Memory Warning What

How to config NSURLSessionConfiguration into the NSObject class?

℡╲_俬逩灬. 提交于 2019-12-06 13:07:56
i want to get server response from NSObject when i m getting a response,it has return to viewController.as i implement on server call into NSObject class then i called to the NSObject method but before server response my NSString have been return as null . NSObject class : @interface getServerCallClassMethod : NSObject<NSURLSessionDelegate> { NSString *ResponceStr; } -(NSString *)getServerCall:(NSString *)mobleNo serverUrl:(NSString *)url; @end implement part : @implementation getServerCallClassMethod -(NSString *)getServerCall:(NSString *)mobleNo serverUrl:(NSString *)url{

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

AFHTTPSessionManager posting video swift

痞子三分冷 提交于 2019-12-06 12:31:20
问题 I am trying to upload a video in background using AFNetworking > AFHTTPSessionManager Post method. I want it to conitune uploading even if the app is suspended. But I get error while executing this code, it logs no error, and points to nowhere in code. I tried every solution available on other posts regarding my scenario, but couldn't get it working. Plesae check my code below and suggest me solution or link me somewhere to make it work { let urlString = BaseUrl + WebLinks.post let appId =

NSURLSessionConfiguration timeoutIntervalForRequest doesn't seem to work with the background session

落花浮王杯 提交于 2019-12-06 12:31:06
The new timeout property of NSURLSessionConfiguration doesn't seem to work when the session is set to work in background (via backgroundSessionConfiguration call). Anybody know if that's really the case? Code snippet: NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:bgSessionConfigIdentifier]; sessionConfig.HTTPMaximumConnectionsPerHost = 1; sessionConfig.timeoutIntervalForRequest = 60; Do I need to do anything extra for the timeout to work? I just ran into similar problem, fixed it by using timeoutIntervalForResource instead of

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

Client certificate authentication in swift2

扶醉桌前 提交于 2019-12-06 10:17:27
问题 I want to authenticate client certificate in my app. I am getting the following errors in didReceiveChallenge function. I found this solution in this link. My didReceiveChallenge func code: func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) { if challenge.protectionSpace.authenticationMethod == (NSURLAuthenticationMethodServerTrust) { let serverTrust

'initWithRequest:delegate:' is deprecated: first deprecated in iOS 9.0 - use NSURLSession(see NSURLSession.h)

天涯浪子 提交于 2019-12-06 08:59:29
i am new in objective C and using iOS 9 Xcode 7.2 and getting this warning "'initWithRequest:delegate:' is deprecated: first deprecated in iOS 9.0 - use NSURLSession(see NSURLSession.h)" how to solve it. my code is given below. +(id)createGetConnectionWithName:(NSString*)strConnectionName_ withUrl:(NSString *)pageUrl parameterNames:(NSArray *)arrParamNames parameterValues:(NSArray *)arrParamValues delegate:(id)delegate { NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"%@",pageUrl]]; NSMutableString *post =[NSMutableString string]; for(int i=0;i<[arrParamNames count];i++) { if(i==