[英]iOS - SDK - How do I open large keynote files in UIWebView?
我正在嘗試將一個大的Keynote文件(~150MB)加載到UIWebView
並且我不斷收到內存警告和我的應用程序崩潰。
有沒有解決的辦法?
打開這么大的文件而不在另一個應用程序中打開它們的正確方法是什么?
直接從URL打開UIWebView
的文件時,下載的內容會臨時存儲在RAM中。 RAM是整個設備的共享空間,必須執行其他與操作系統相關的任務。 因此,由於內存壓力和資源緊張,您的應用程序被iOS殺死。
建議在后台將您的內容直接寫入NSDocumentsDirectory
中的文件,然后在UIWebView
加載該文件。
據我所知,我可以建議你以下。
下載部分
預覽部分
希望有所幫助。
如果它是一個大文件,你不能/不應該使用UIWebView
。
為什么? 我試圖顯示一個帶有幾個圖像的文檔文件(docx),並且在拋出內存警告后我的應用程序崩潰了。 原因很簡單。 雖然文件大小約為2.5 MB,但設備沒有足夠的RAM /內存來顯示所有位圖圖像(嵌入在文檔中)。 使用Instruments調試問題表明,應用程序內存從30 MB增加到230 MB。 我想你正在經歷類似的事情。
可能的解決方案:
不允許用戶在其移動設備上打開大文件。 當您收到內存警告時,或者正常停止/暫停UIWebView
加載過程。
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; if ([self.webView isLoading]) { [self.webView stopLoading]; } }
請嘗試使用[UIApplication sharedApplication] openURL:]
方法。
請嘗試使用UIDocumentInteractionController
。
UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:targetURL]; documentInteractionController.delegate = self; BOOL present = [documentInteractionController presentPreviewAnimated:YES]; if (!present) { // Allow user to open the file in external editor CGRect rect = CGRectMake(0.0, 0.0, self.view.frame.size.width, 10.0f); present = [documentInteractionController presentOpenInMenuFromRect:rect inView:self.view animated:YES]; if (!present) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Cannot preview or open the selected file" delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil, nil]; [alertView show]; } }
注意:我沒有嘗試使用上述方法打開主題文件。 要使用UIDocumentInteractionController
,您必須先下載該文件。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.