2011-06-21 32 views
1

我想知道是否可以創建支持打開.html頁面的應用程序。在html中打開(在Safari中)

例如,如果應用程序支持.pdf,當打開.pdf時,會出現一個小小的灰色方框,並顯示按鈕「在myApp中打開」。我可以得到這樣的東西,但後來的網頁?

回答

2

嗯,你說的是UIDocumentInteractionController那麼。
實施UIDocumentInteractionControllerDelegate在UIViewController

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { return self; } 
- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller { return self.view; } 
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller { return self.view.frame; } 

然後添加一個按鈕,導航欄,彈出選項對話框:

// example: opening a .html file 
NSString *index = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]; 

// self.controller is a UIDocumentInteractionController ivar 
self.controller = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]]; 
self.controller.delegate = self; 
CGRect rect = self.navigationController.navigationBar.frame; 
rect.size = CGSizeMake(1500.0f, 40.0f); // move the box right down under the button 
[self.controller presentOptionsMenuFromRect:rect inView:self.view animated:YES]; 

支持特定文件應出現在應用程序的列表。如果您沒有註冊您的應用程序以支持某種類型的文檔,您仍然可以選擇「QuickLook」選項。所有這些都發生在與文件交互的任何應用程序上(因爲文件本身並未在UI上公開)。

+0

灰色矩形會自動顯示,因爲該應用程序支持.pdf文件(適用於該包)。這不是我編程的東西,iOS顯示灰色框,並可以在我的應用程序中打開它。那時候,我的應用程序可能還沒有開始。我希望對.html文件具有相同的功能 – Joetjah