nsurlprotocol

How to mock AJAX call with NSURLProtocol?

好久不见. 提交于 2019-12-17 18:27:12
问题 I have UIWebview that makes AJAX calls to external services. When offline i need to catch theses requests and return local json. I implemented a NSURLProtocol and i manage to catch the AJAX request, the problem is jquery always return a 0 error code : $.ajax({ url: url, dataType: 'json', contentType: "application/json", success: function(jsonData){ alert("success :"); }, error: function (request, status, error) { alert("failure :" + request.status ); } }); I always get a request.status = 0 To

Loading resources from relative paths through NSURLProtocol subclass

拈花ヽ惹草 提交于 2019-12-13 17:58:41
问题 I have an NSURLProtocol registered for a UIWebView-based app, set up to respond to file scheme requests. In the web view, I load images, CSS, JS etc. and all that's all working fine; the problem comes when I try to reference an image in a CSS file that's not at the root directory of the HTML tree. E.g. <html> <head> <style type="text/css"> .1 { background-image: url("1.png"); } </style> <link href="css/style.css" rel="stylesheet" type="text/css" /> <!-- contents of css/style.css might be: .2

Using NSURLProtocol to implement play while downloading for AVPlayer on iOS

£可爱£侵袭症+ 提交于 2019-12-13 15:26:34
问题 I'm trying to play a mp4 video on my server and I'd like to cache this video to disk simultaneously. I know that I can just use 2 requests to do this, one for download another one created by AVPlayer to play the video, but this will waste the network bandwidth. So I need to use just one outer request to download the data and capture all NSURLRequest from AVPlayer in MyNSURLProtocol and manually create NSHTTPURLResponse for them. This is how the workflow looks like: AVPlayer <-->

NSURLProtocol canInitWithRequest: called multiple times

懵懂的女人 提交于 2019-12-12 08:35:05
问题 Our app has a lot of web views in it and I recently added a NSURLProtocol to interceptor some of the requests from them. I've noticed that some of the web views are calling the +[NSURLPRotocol canInitWithRequest:] method multiple times with what appears to be exactly the same request. Sometimes 6 or 7 times. I'm trying to figure out why this might be occurring. Does anyone have any experience with this? I've logged out the [NSURL absoluteString] and httpMethod values and they are the same for

Custom URL scheme as adapter on existing URL schemes

不想你离开。 提交于 2019-12-11 08:36:05
问题 Is there a clean and spec-conformant way to define a custom URL scheme that acts as an adapter on the resource returned by another URL? I have already defined a custom URL protocol which returns a decrypted representation of a local file. So, for instance, in my code, decrypted-file:///path/to/file transparently decrypts the file you would get from file:///path/to/file . However, this only works for local files. No fun! I am hoping that the URL specification allows a clean way that I could

Correlate NSURLRequest with UIWebView

ぃ、小莉子 提交于 2019-12-10 14:47:14
问题 In iOS, I'd like to be able to associate an NSURLRequest -- any NSURLRequest , whether a navigation request or image or stylesheet request--with the UIWebView that sent it. This seems to call for the implementation of an NSURLProtocol subclass to capture and analyze requests as they come through. However, I can't find a way to correlate a request with its web view, and NSURLProtocol only seems to understand NSURLRequest s. This would be fine for navigation requests, as I could make the

Using NSURLSession inside NSURLProtocol

元气小坏坏 提交于 2019-12-10 12:23:23
问题 I'm trying to create a transparent NSURLProtocol for http:// and https:// connections using NSURLSession. However at the moment, even though the completion handler is being run, URL requests with the app (UIWebView) are coming back blank. Does anybody have any ideas? Code is below: #import "MyURLProtocol.h" // AppDelegate #import "AppDelegate.h" static NSString * const MyURLProtocolHandledKey = @"MyURLProtocolHandledKey"; @interface MyURLProtocol () <NSURLConnectionDelegate

How to get requesting UIWebView from inside of NSURLProtocol

[亡魂溺海] 提交于 2019-12-07 08:04:17
问题 My app uses subclassing of NSURLProtocol. There are several UIWebViews in the app and for specific algorithm implemented in NSURLProtocol I need to know which one of the UIWebViews sends the request. My understanding is that object returned by [self client] should be somewhat connected with requesting object. But neither NSURLProtocolClient (that is the protocol implemented by object returned by [self client]) nor underlying object _NSCFURLProtocolBridge have any properties/methods to get the

NSURLSessionTask authentication challenge completionHandler and NSURLAuthenticationChallenge client

感情迁移 提交于 2019-12-06 06:08:48
问题 I am implementing a custom NSURLProtocol , and internally want to use NSURLSession with data tasks for internal networking instead of NSURLConnection . I have hit an interesting problem and wonder about the internal implementation of the challenge handler of NSURLSession / NSURLSessionTask . - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition

How to get requesting UIWebView from inside of NSURLProtocol

牧云@^-^@ 提交于 2019-12-05 18:18:11
My app uses subclassing of NSURLProtocol. There are several UIWebViews in the app and for specific algorithm implemented in NSURLProtocol I need to know which one of the UIWebViews sends the request. My understanding is that object returned by [self client] should be somewhat connected with requesting object. But neither NSURLProtocolClient (that is the protocol implemented by object returned by [self client]) nor underlying object _NSCFURLProtocolBridge have any properties/methods to get the sender of the request. Can anyone help me with ideas? Pradeep NSURLRequest has a method called