2011-07-20 17 views
3

特定のファイルタイプを扱うことができるデバイス上で使用可能なアプリケーションの数を確認できますか?基本的には、アプリケーションに別のアプリケーションを開くためのボタンがありますが、ドキュメントを開くアプリケーションがない場合は表示しません。UIDocumentInteractionControllerにオプションがありません

答えて

5

醜い醜いハックが、動作するようだ...より良い方法を見つけるのが大好きです。

拡張のためのヘッダファイルを作成します。

// UIDocumentInteractionController+willShowOpenIn.h 

#import <Foundation/Foundation.h> 

@interface UIDocumentInteractionController (willShowOpenIn) 
- (BOOL)willShowOpenIn; 
+ (BOOL)willShowOpenInForURL:(NSURL *)filePathURL; 
@end 

・実施:次に

// UIDocumentInteractionController+willShowOpenIn.m 

#import "UIDocumentInteractionController+willShowOpenIn.h" 

@implementation UIDocumentInteractionController (willShowOpenIn) 
- (BOOL)willShowOpenIn 
{ 
    id <UIDocumentInteractionControllerDelegate> oldDelegate = self.delegate; 
    self.delegate = nil; 
    UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; 
    if([self presentOpenInMenuFromRect:window.bounds inView:window 
          animated:NO]) 
    { 
     [self dismissMenuAnimated:NO]; 
     self.delegate = oldDelegate; 
     return YES; 
    } 
    else { 
     self.delegate = oldDelegate; 
     return NO; 
    } 
} 

+ (BOOL)willShowOpenInForURL:(NSURL *)filePathURL 
{ 
    UIDocumentInteractionController *tempController = [UIDocumentInteractionController interactionControllerWithURL:filePathURL]; 
    return [tempController willShowOpenIn]; 
} 
@end 

使用:

#import "UIDocumentInteractionController+willShowOpenIn.h" 

...

NSURL *testURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"]]; 
NSLog(@"Will show - %@",[UIDocumentInteractionController willShowOpenInForURL:testURL] ? @"YES" : @"NO"); 

もっと良い方法があることを教えてください:)

+0

これはアプリストアにこれまでに行ったことがありますか? – FaddishWorm

+0

App Storeで問題はありません。しかし、任意のハックのように、任意の日を壊すことができる:) – BadPirate

関連する問題