0
我的應用程序使用UIWebView加載網站和下載文件,當用戶點擊下載鏈接時,應用程序凍結,直到文件完成下載,然後應用程序恢復正常,它不會崩潰,它只是凍結。我解決這個問題?下載文件時UIWebView鎖定/凍結/掛起應用程序?
即時通訊使用此代碼下載從蘋果iOS 5.1的文檔
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if(navigationType == UIWebViewNavigationTypeLinkClicked)
{
NSURL *requestedURL = [request URL];
// ...Check if the URL points to a file you're looking for...
// Then load the file
NSData *fileData = [[[NSData alloc] initWithContentsOfURL:requestedURL] autorelease];
// Get the path to the App's Documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
[fileData writeToFile:[NSString stringWithFormat:@"%@/%@", documentsDirectory, [requestedURL lastPathComponent]] atomically:YES];
}
return YES;
}
- (NSString *)documentsDirectoryPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
return documentsDirectoryPath;
}
你有很大的數據很頻繁地寫入目錄嗎? –