//下载文件
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer.timeoutInterval = 60;
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSString * URL=[self.DocDownUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[manager GET:URL parameters:@"" progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// 获取数据流,写入本地
[self writeToFile:responseObject fileName:nameStr];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//"%@",error);
}];
//写入文件并打开
-(void)writeToFile:(NSData *)data fileName:(NSString *)fileName{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * _filePath = [paths objectAtIndex:0];
fileName = [NSString stringWithFormat:@"%@",fileName];
NSString * filePath = [_filePath stringByAppendingPathComponent:fileName];
NSURL * fileUrl=[NSURL URLWithString:@""];
// NSData写入文件
[data writeToFile:filePath atomically:YES];
//NSLog(@"fileDataPath is %@", filePath);
if (@available(iOS 9.0, *)) {
[self.wkWebView loadFileURL:fileUrl allowingReadAccessToURL:[NSURL fileURLWithPath:filePath]];
}
}