我已存儲的文件(PDF)中的「文檔」目錄,我想知道,怎麼可能,如果有應用程序來檢測前打開一個文件(應用程序)安裝在可以打開此文件的移動設備中(例如,可以使用「iBooks」,「DropBox」...)打開「pdf」文件。我想在調用方法「presentOpenInMenuFromRect」之前檢測這個;其中顯示了可以處理特定文件的可能應用程序的列表。期望的行爲是:檢查它是否存在的應用程序,可以調用presentOpenInMenuFromRect
1)鑑於存儲在「文檔」目錄中的pdf,檢查是否在iPhone/iPad中安裝了「應用程序」,可以打開該文件(iBooks,DropBox,...) 。這是我不知道該怎麼做的。 2)如果在iPhone/iPad上沒有應用程序可以打開應用程序,則什麼也不做,否則畫一個「保存」按鈕,然後,如果用戶按下這個「保存」按鈕,那麼「presentOpenInMenuFromRect」方法將會被調用以顯示可以打開該文件的可能應用的列表。我知道如何呈現可以打開文件的應用程序列表;這裏的源代碼:
相關的「保存」按鈕的源代碼是:
- (void) saveFile:(UIWebView*)webView
{
NSString* fileName = [[NSFileManager defaultManager] displayNameAtPath:webView.request.URL.absoluteString];
#if DEBUG
NSLog(@"<%p %@: %s line:%d> File name:%@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, fileName);
#endif
NSURL* fileurl = [NSURL URLWithString:webView.request.URL.absoluteString];
NSData* data = [NSData dataWithContentsOfURL:fileurl];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* docsDirectory = [paths objectAtIndex:0];
NSString* filePath = [docsDirectory stringByAppendingPathComponent:fileName];
[data writeToFile:filePath atomically:YES];
NSURL* url = [NSURL fileURLWithPath:filePath];
//UIDocInteractionController API gets the list of devices that support the file type
docController = [UIDocumentInteractionController interactionControllerWithURL:url];
[docController retain]; //Very important, if "retain" is not called, the application crashes
//Present a drop down list of the apps that support the file type,
//clicking on an item in the list will open that app while passing in the file.
BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:webView animated:YES]; //Using "webView" instead of "self.view"
if (!isValid)
{
[self showAlertSaveFileError:fileName]; //Shows an alert message
}
}
在此先感謝。
注意:調用方法「presentOpenInMenuFromRect」的響應時間大約是幾秒鐘,所以這就是爲什麼我想知道是否有另一種方法來檢測並獲取安裝在應用程序上的可能應用程序的列表移動設備可以打開一個特定的文件(PDF,...)
的iHasApp網站說,已不再符合AppStore的和已經停產。 –