当用户单击下载链接时,我的应用程序使用 UIWebView 加载网站并下载文件,应用程序冻结直到文件完成下载,然后应用程序恢复正常,它不会崩溃,它只是冻结.. 我该如何解决这?
我使用此代码下载
- (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;
}