文件不会下载,并且不会显示文件中存在的任何信息。有时它会显示一条消息,即文件已损坏或文件类型未知。
injurydocObj=[self.injuryDocSN objectAtIndex:indexPath.row];
NSString *path = injurydocObj.athleteDoumentPath;
NSString *fileName=injurydocObj.documentName;
path = [path stringByReplacingOccurrencesOfString:@"\\"
withString:@"/"];
path = [path stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *strFileType=@"";
NSArray *arFileName = [fileName componentsSeparatedByString:@"."];
if(arFileName.count>0)
{
strFileType = arFileName[arFileName.count-1];
strFileType = [strFileType lowercaseString];
}
if([strFileType isEqual:@"doc"] || [strFileType isEqual:@"docx"] || [strFileType isEqual:@"pdf"]){
NSURLRequest *requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:path]];
}`请帮助我显示pdf,doc和docx文件类型,即使文件名包含特殊字符或空格
发布于 2019-07-12 18:02:59
使用专用接口stringByAddingPercentEncodingWithAllowedCharacters添加百分比编码
NSString *path = injurydocObj.athleteDoumentPath;
NSString *fileName = injurydocObj.documentName;
path = [[path stringByReplacingOccurrencesOfString:@"\\" withString:@"/"]
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString: path];
if ([@[@"doc", @"docx", @"pdf"] containsObject: url.pathExtension]) {
...
NSURLRequest *requestObj = [NSURLRequest requestWithURL: url];https://stackoverflow.com/questions/57003032
复制相似问题