iPhone SDK:从自定义 URL 方案加载资源 [英] iPhone SDK: Loading resources from custom URL scheme

查看:21
本文介绍了iPhone SDK:从自定义 URL 方案加载资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 HTML 字符串,它是由第三方库使用 xml 文件创建的.HTML 字符串包含图像和视频的自定义 URL(例如:image://).有什么办法可以处理这些资源加载请求并在 UIWebView 中正确加载它们吗?

I have HTML string which is created using an xml file by a third party library. The HTML string contains custom URLs for images and videos (Ex:image://). Is there is way by I can handle these resource load request and load them correctly in UIWebView?

推荐答案

我们需要创建一个 NSURLProtocol 的子类,并重新实现以下可以处理自定义 URL 方案的方法

We need to create a subclass of NSURLProtocol and re-implement the following methods that can handle the custom URL scheme

+(BOOL)canInitWithRequest:(NSURLRequest*)request
+(NSURLRequest*)canonicalRequestForRequest:(NSURLRequest*)request
+(BOOL)requestIsCacheEquivalent:(NSURLRequest*)a toRequest:(NSURLRequest*)b
-(void)startLoading
-(void)stopLoading

当应用以下列方式启动时,我们还必须注册这个自定义 URL 协议类

We also have to register this custom URL protocol class when the app launches in the following way

[NSURLProtocol registerClass:[CustomURLProtocol class]];

这篇关于iPhone SDK:从自定义 URL 方案加载资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆