0
我正在爲Ios開發一個Epub Reader,注意我沒有使用任何epub庫,並且我自己解析了epub。Ios通過NSURLCache攔截UIWebview請求並替換響應
我需要一個從epub加載資源到UIWebView
的方法,例如圖片或CSS文件...(在html文件中請求的資源)。
爲此,我決定使用NSURLCache
類並重寫它的方法(NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request
,所以我可以攔截請求,並從EPUB找到正確的數據,然後創建一個NSCachedURLResponse
並返回。
迄今爲止好。 但是問題在於數據(即圖像)不會顯示在web視圖中。看看下面的代碼:
- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request
{
/*
the request.URL is something like this applewebdata://UUID/OEBPS/Images/cover.jpg ,
so the getResourcePathFromRequest give me the path OEBPS/Images/cover.jpg,
so i can find the right data in epub
*/
NSString *resourcePath = [self getResourcePathFromRequest:request.URL];
/*
ResourceResponse is a class contaning data and mimeType,
i tested this and the data and mimeType are good so this is not the problem
*/
ResourceResponse *response = [[self getBook] fetch:resourcePath];
NSURLResponse *urlResponse = [[NSURLResponse alloc] initWithURL:[request URL] MIMEType:response.mMimeType expectedContentLength:[response.mData length] textEncodingName:@"UTF-8"];
NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:urlResponse data:response.mData];
return cachedResponse;
}
在這一點上一切看起來都很正常,該方法獲取調用,被找到了正確的數據和響應對象的回報,但它的圖像不會加載到web視圖。
那麼是什麼問題?
tnx提前。
注意:我是新的IOS編程世界(從Android的未來:)