
注意:我已经检查了这个问题,其中的问题与多次加载相同的内容有关.
NSURLProtocol isn’t asked to load after YES response to canInitWithRequest
实际页面在我的自定义NSURLProtocol中加载很好,它从canInitWithRequest返回YES(几次),然后在大约第4或第5次后调用startLoading.然后它以类似的方式加载我的CSS文件.然后我看到我的视频对象的请求从canInitWithRequest返回YES,但没有任何反应.永远不会为我的视频资源请求调用startLoading.这是我加载页面时设备的简化日志:
canInitWithRequest: https://WebpageURLcanInitWithRequest: https://WebpageURLcanInitWithRequest: https://WebpageURLcanInitWithRequest: https://WebpageURLcanInitWithRequest: https://WebpageURLSTART LOADING: https://WebpageURLcanInitWithRequest: https://WebpageURLcanInitWithRequest: https://WebpageURLcanInitWithRequest: https://WebpageURLcanInitWithRequest: https://CSSResourceSTART LOADING: https://CSSResourcecanInitWithRequest: https://MyVIDeoResource
当我从完全相同的设备类型运行相同iOS版本的模拟器加载完全相同的页面时,日志显示资源实际上由于某种原因开始加载:
canInitWithRequest: https://WebpageURLcanInitWithRequest: https://WebpageURLcanInitWithRequest: https://WebpageURLSTART LOADING: https://WebpageURLcanInitWithRequest: https://WebpageURLcanInitWithRequest: https://CSSResourceSTART LOADING: https://CSSResourcecanInitWithRequest: https://MyVIDeoResourcecanInitWithRequest: https://MyVIDeoResourceSTART LOADING: https://MyVIDeoResource -- WHY NOT ON DEVICE?
该页面留下了一个永远不会播放的视频 – 只有一个白色的盒子,它上面有“播放视频”按钮.页面看起来像是不断加载某些东西(状态栏中的活动指示器正在旋转)但没有发生任何事情,并且Xcode的DeBUG导航器中的网络活动是扁平化的.
TL;博士
有谁知道为什么从未在我的iPhone上尝试加载此资源?显然,模拟器知道它需要加载.
编辑:这是来自我的NSURLProtocol的略微编辑的相关代码
@implementation CHhttpURLProtocol{ NSURLConnection *connection; NShttpURLResponse *httpResponse; NSData *responseData;}+ (BOol)canInitWithRequest:(NSURLRequest *)request{ if (/* key exists on request */) return NO; else if (/* not http or https */) return NO; NSLog(@"canInitWithRequest: %@",request.URL.absoluteString); return YES;}+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request{ return request;}- (voID)startLoading{ NSMutableURLRequest *request = [self.request mutablecopy]; NSLog(@"START LOADING: %@",request.URL.absoluteString); if (authenticate) authenticate(request); /* add key to request */ connection = [NSURLConnection connectionWithRequest:request delegate:self];}- (voID)stopLoading{ [connection cancel]; connection = nil;}/* Other methods like connection:dIDReceiveData: and connectionDIDFinishLoding: */+ (voID)authenticateWithBlock:(AuthenticationBlock)block{ authenticate = block;}static AuthenticationBlock authenticate;解决方法 我最好的猜测是UIWebVIEw中使用的视频播放器没有使用通过NSURProtocol管道的Foundation服务(NSURLSession / NSURLRequest等)加载它的内容.可能视频播放器正在使用较低级别的CFNetwork API发出请求. 实现可能因模拟器而异.
我得到你的协议使用canInitWithRequest调用进行轮询,但这并不一定意味着玩家将使用NSURLSession / NSURLRequest实际加载资源.
尝试通过自定义协议将视频加载到MPMovIEPlayerVIEwController中的行为与您所看到的类似:How to play movie with a URL using a custom NSURLProtocol?
总结以上是内存溢出为你收集整理的ios – NSURLProtocol – 在canInitWithRequest为页面资源返回YES之后未调用startLoading全部内容,希望文章能够帮你解决ios – NSURLProtocol – 在canInitWithRequest为页面资源返回YES之后未调用startLoading所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)