我们有一个代码可以使用SOAP协议从服务器下载PDF。从iOS应用程序打开文件查看器(PDF)
我们存储在iOS设备的文档文件夹中的文件,以及我们希望允许用户打开该文件(通常是PDF格式的文件)
但是,至少在模拟器上,应用程序没” t成功打开文件。
当然,我可以手动打开该文件(为了检查该文件已被完全下载)
// Get the documents folder where write the content
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:documentDownloaded.fileName];
if ([[NSFileManager defaultManager] fileExistsAtPath:[self getFileCompletePath]]){
NSString *filePath = [[NSString alloc] initWithFormat:@"%@", [self getFileCompletePath]];
NSURL *url = [[NSURL alloc] initFileURLWithPath:filePath];
if ([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL: url];
} else {
NSLog(@"Not supported application to open the file %@", filePath);
}
[url release];
[filePath release];
}
在模拟器的文件的完整路径是:
/用户/用户/ Library/Application Support/iPhone Simulator/4.3.2/Applications/87800296-2917-4F26-B864-B20069336D1D/Documents/0000907.pdf
任何人都知道是否有问题?
该文件可能是和电子表格,pdf,图像,文档......但对于第一个解决方法将是伟大的只是PDF的。
谢谢
昨天我在读关于苹果库这个组件,我今天检查,但是...如果我没有错,当我使用这个代码行... //获取写入内容的文档文件夹 NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString * documentsDirectory = [paths objectAtIndex:0]; 我正在访问用户文档文件夹,而不是应用程序文档文件夹。 –