在我的应用程序中,我需要允许用户浏览本地或文档目录中存储的一些PDF文件。从iPhone浏览PDF文件
想要放一个按钮,当用户点击该按钮时,它显示PDF文件并附加该文件并将其发送到服务器[例如:在Gmail中附加文档]。
我该如何实现this.help我。感谢提前。
在viewdidload /////下载文件目录中的pdf文件。
NSString *stringURL = @"http://www.khazanah.com.my/khazanah/files/20/200f21f3-07ff-4903-ab99-7c0cb557eb51.pdf";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if (urlData)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"filename.pdf"];
NSLog(@"filePath %@",filePath);
[urlData writeToFile:filePath atomically:YES];
}
在文档目录中获取文件。
-(IBAction)favbtnClicked:(id)sender
{
NSString *searchFilename = @"filename.pdf"; // name of the PDF you are searching for
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:documentsDirectory];
NSString *documentsSubpath;
while (documentsSubpath = [direnum nextObject])
{
if (![documentsSubpath.lastPathComponent isEqual:searchFilename]) {
continue;
}
NSLog(@"found %@", documentsSubpath);
}
}
documentsSubpath字符串得到该pdf文件如何显示在UICollectionView。帮我。
您只能浏览.pdf目前在您的APP中。你知道自己在哪里.pdf,那么你的问题是什么? – Larme
好的...该文件不在我的应用程序如何浏览文件 – saravanar
你不能。它被称为沙箱,iOS没有“Finder.app”/ Explorer等效。看到那里:http://stackoverflow.com/questions/38873128/how-to-choose-pdf-file-in-ios – Larme