2017-01-20 98 views
0

如何檢索實際的文件/數據這樣decidePolicyForNavigationResponse委託方法裏面的一些檢查後:如何下載文件/數據從驗證「CONTENT_TYPE」後** ** decidePolicyForNavigationResponse在WKWebview:

- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler 
    { 

      NSHTTPURLResponse *response = (NSHTTPURLResponse *)navigationResponse.response; 

    } 

歡迎任何線索...謝謝你

回答

0

我是個初學者,但如果你想下載一個WKWebview一個文件,你需要使用AFNetworking,代碼如下所示:

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; 
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration]; 

    NSURL *URL = WebView.URL; 
    NSURLRequest *request = [NSURLRequest requestWithURL:URL]; 

    NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) { 
     NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; 
     return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]]; 
    } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) { 
     NSLog(@"File downloaded to: %@", filePath); 
    }]; 
    [downloadTask resume]; 

希望這對你有所幫助