nsurlrequest

Cache for WKWebView

≯℡__Kan透↙ 提交于 2019-12-18 04:37:30
问题 I am having trouble with my custom internet browser. I am using WKWebView. I have tabs in my app. If I click on a tab new NSURLRequest loads in the WKWebView. I need to implement a cache. If a user presses on a tab, I'd prefer to load a cache data instead of new. Unfortunately this code doesn't work: NSURLRequest *request = [[NSURLRequest alloc] initWithURL:URL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:0.0]; [self.webView loadRequest:request]; Can you guide me on how to

How to insert header info into MPMoviePlayerController url?

笑着哭i 提交于 2019-12-18 03:46:54
问题 I need to implement video streaming service with http protocol. I know how to set url into MPMoviePlayerController, and how to set headerField into NSMutableURLRequest, but I have no idea how to combine them. I implement like below code, but not working, and I assume because there is no file info in the binary data. - (void) openUrl { NSMutableURLRequest *reqURL = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:@"http://111.222.33.44/MOV/2013/4/123123123"] cachePolicy

NSURL found nil while unwraping an Optional value

孤街醉人 提交于 2019-12-17 20:45:15
问题 Anyone knows why am I getting fatal error: unexpectedly found nil while unwrapping an Optional value When i use let URL = NSURL(string: "https://roads.googleapis.com/v1/snapToRoads?path=-35.27801,149.12958|-35.28032,149.12907")! 回答1: The | character its not a valid URL character so you must replace it with percent escape character. Encoding whole string will do that automatically for you var stringUrl = "https://roads.googleapis.com/v1/snapToRoads?path=-35.27801,149.12958|-35.28032,149.12907"

Swift 2.0 NSURLConnection sendSynchronousRequest

妖精的绣舞 提交于 2019-12-17 20:33:21
问题 I am using the code below to check for an internet connection. It was working correctly but after the Swift 2.0 update I now see an error on the line var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: nil) as NSData? saying extra argument 'error' in call. class func isConnectedToNetwork()->Bool{ var Status:Bool = false let url = NSURL(string: "http://google.com/") let request = NSMutableURLRequest(URL: url!) request.HTTPMethod = "HEAD" request

function with dataTask returning a value

孤人 提交于 2019-12-17 19:54:20
问题 I wan't to check if my url statusCode equals to 200, I created a function returning a Boolean if the statusCode equals to 200, I'm using a dataTask, but I don't know how to return a value: class func checkUrl(urlString: String) -> Bool{ let urlPath: String = urlString var url: NSURL = NSURL(string: urlPath)! var request: NSURLRequest = NSURLRequest(url: url as URL) var response: URLResponse? let session = Foundation.URLSession.shared var task = session.dataTask(with: request as URLRequest,

NSURLConnection NSURLRequest proxy for asynchronous web service calls

柔情痞子 提交于 2019-12-17 17:59:16
问题 I have multiple views which make the same NSURLRequest/NSURLConnection request . Ideally, in order to get some code reuse, I'd like to have some sort of a "proxy" which does all the underlying work of creating/executing the (asynchronous) request/connection, setting up all the delegate methods, etc., so I don't have to copy all those NSURLConnection delegate method handlers in each view. First of all, is this design approach reasonable? Second, how would I go about doing something like that?

UIWebView webpage caching for offline viewing

好久不见. 提交于 2019-12-17 08:59:08
问题 First of all, I'm pretty sure that I have checked every answer here and nothing does what I would like to do. In this question, for answer is given ASIHTTPRequest which is dead project. (How do I download an entire webpage (with images) on the iPhone?) In this question, user proposed RNCachingURLProtocol which is really great but I had a few problems after closing app completely (closing it in task-bar). After that I didn't get css or images, only html was loaded. (Cache a single webpage for

NSURLRequest : Post data and read the posted page

一曲冷凌霜 提交于 2019-12-17 07:13:03
问题 In iOS (current target 5.0, Base SDK 5.1) how can I send a post request to a server, and then read the contents of the page. For example, the page takes a username and password, and then echos true or false. This is just for a better understanding of NSURLRequest. Thanks in Advance! 回答1: A few things first Decide how you want to encode your data - JSON or url-encoding are a good start. Decide upon a return value - will it be 1, TRUE or 0, FALSE, or even YES/non-nil nothing/nil. Read up on the

NSMutableURLRequest not obeying my timeoutInterval

牧云@^-^@ 提交于 2019-12-17 07:07:57
问题 I'm POST'ing a small image, so i'd like the timeout interval to be short. If the image doesn't send in a few seconds, it's probably never going to send. For some unknown reason my NSURLConnection is never failing, no matter how short I set the timeoutInterval . // Create the URL request NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.tumblr.com/api/write"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:0.00000001]; /*

Why my return is nil but if i press the url in chrome/safari, i can get data?

那年仲夏 提交于 2019-12-17 05:14:52
问题 @IBAction func mainButtonnBeTapped(sender: AnyObject) { let session = NSURLSession.sharedSession() let request = NSURLRequest(URL: NSURL(string: "http://hq.sinajs.cn/list=sz000609")!) let task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in let myString = NSString(data: data, encoding: NSUTF8StringEncoding) println("this is my string: \(myString)") }) task.resume() } I am using above url to try to get some data, but the return is nil, but i enter