1. Whether: Txt,epub,pdf and other formats of the file, save to the local time, it is best to save into letters or numbers, do not save into Chinese characters, otherwise, in the file, due to the problem of coding, various watts
2. If the file name is actually saved as a Chinese character, the Transcoding method is:
[FileName stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]; // no such processing will return nil];
3.pdf Pit: Because the file format returned in the background is DAT, you need to locally dynamically determine the file format, so when judging the PDF, there are a lot of problems
1. In the conversion between Nsurl and filepath, although FilePath is a string, but can not use url.absolutestring this method, should be used url.path this method, or the subsequent access to the file
When the string goes to the URL, this is:
[Nsurl Urlwithstring:_model.filepath]
2. Replace. dat in the file path with. pdf, no eggs:
[Afilepath stringbyreplacingoccurrencesofstring:@ ". Dat" withstring:@ " . pdf "]
File name must be renamed
//get a local PDF file+ (Cgpdfdocumentref) Pdfrefbyfilepath: (NSString *) afilepath{//cfurlref Pdfurl = Cfbundlecopyresourceurl (Cfbundlegetmainbundle (), (__bridge cfstringref) [AFilePath LastPathCom Ponent], NULL, (__bridge cfstringref) @ "files");//cgpdfdocumentref pdfdocument = Cgpdfdocumentcreatewithurl ((cfurlref) pdfurl);// cfstringref Path; Cfurlref URL; Cgpdfdocumentref document; size_t count; //the PDF extension must be renamed before it can be taken to thensstring* aFilePath2 = [Afilepath stringbyreplacingoccurrencesofstring:@". Dat"Withstring:@". pdf"]; Nserror*error; //[[Nsfilemanager Defaultmanager] moveitematpath:afilepath2 topath:afilepath2 Error:nil];nsfilemanager* FileManager =[Nsfilemanager Defaultmanager]; if([FileManager Fileexistsatpath:afilepath]) {//get new resource path with different extension//copy it over[FileManager Copyitematpath:afilepath topath:afilepath2 error:&ERROR]; } Path=cfstringcreatewithcstring (NULL, [AFilePath2 utf8string], Kcfstringencodingutf 8); URL=Cfurlcreatewithfilesystempath (NULL, Path, Kcfurlposixpathstyle,0); Cfrelease (path); Document=cgpdfdocumentcreatewithurl (URL); Cfrelease (URL); if(Document = =Nil) {[FileManager copyitematpath:afilepath2 topath:afilepath Error:&ERROR]; } //nsstring* FilePath = [Afilepath stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];//cfstringref Path;//cfurlref URL;//Cgpdfdocumentref document;//FilePath = [Afilepath stringbyreplacingoccurrencesofstring:@ ". Dat" withstring:@ ". pdf"];//path = cfstringcreatewithcstring (NULL, [FilePath utf8string], kCFStringEncodingUTF8);//url = cfurlcreatewithfilesystempath (NULL, Path, Kcfurlposixpathstyle, 0);//cfrelease (path);//document = Cgpdfdocumentcreatewithurl (URL);//cfrelease (URL); returndocument; }
IOS gets various pits for local files