我們有一個代碼可以使用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]; 我正在訪問用戶文檔文件夾,而不是應用程序文檔文件夾。 –