@@ -47,23 +47,12 @@ - (BOOL)viewFile:(NSString *)filePath usingViewController:(UIViewController *) v
47
47
// Configure Document Interaction Controller
48
48
[self .documentInteractionController setDelegate: self ];
49
49
50
- // Preview PDF
50
+ // Preview
51
51
filePreviewSuccess = [self .documentInteractionController presentPreviewAnimated: YES ];
52
52
53
53
if (!filePreviewSuccess) {
54
- // There is no app to handle this file
55
- NSString *deviceType = [UIDevice currentDevice ].localizedModel ;
56
- NSString *message = [NSString stringWithFormat: NSLocalizedString(@" Your %@ doesn't seem to have any other Apps installed that can open this document." ,
57
- @" Your %@ doesn't seem to have any other Apps installed that can open this document." ), deviceType];
58
-
59
- // Display alert
60
- UIAlertView *alert = [[UIAlertView alloc ] initWithTitle: NSLocalizedString(@" No suitable Apps installed" , @" No suitable App installed" )
61
- message: message
62
- delegate: nil
63
- cancelButtonTitle: NSLocalizedString(@" OK" , @" OK" )
64
- otherButtonTitles: nil ];
65
- [alert show ];
66
- return NO ;
54
+ // Next, try the options menu in openFile below...
55
+ return [self openFile: URL usingViewController: viewController];
67
56
}
68
57
} else {
69
58
return NO ;
@@ -72,6 +61,53 @@ - (BOOL)viewFile:(NSString *)filePath usingViewController:(UIViewController *) v
72
61
return YES ;
73
62
}
74
63
64
+ - (BOOL ) openFile : (NSURL *)URL usingViewController : (UIViewController *) viewController
65
+ {
66
+ self.myViewController = viewController;
67
+
68
+ BOOL fileOpenSuccess = NO ; // Success is true if it was possible to open
69
+
70
+ if (URL) {
71
+ // Initialize Document Interaction Controller
72
+ self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL: URL];
73
+ self.documentInteractionController .UTI = [self UTIForURL: URL];
74
+ self.documentInteractionController .delegate = self;
75
+
76
+ UIView *fileOpenView = [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , 1 , 1 )];
77
+ [[self .myViewController view ] addSubview: fileOpenView];
78
+ self.view = fileOpenView;
79
+
80
+ // Configure Document Interaction Controller
81
+ [self .documentInteractionController setDelegate: self ];
82
+
83
+ // Open
84
+ CGRect screenRect = [[viewController view ] bounds ];
85
+ CGFloat screenWidth = screenRect.size .width ;
86
+ CGFloat screenHeight = screenRect.size .height ;
87
+ fileOpenSuccess = [self .documentInteractionController presentOptionsMenuFromRect: CGRectMake ((screenWidth / 2 ), screenHeight, 1 , 1 ) inView: fileOpenView animated: YES ];
88
+
89
+ if (!fileOpenSuccess) {
90
+ // There is no app to handle this file
91
+ NSString *deviceType = [UIDevice currentDevice ].localizedModel ;
92
+ NSString *message = [NSString stringWithFormat: NSLocalizedString(@" Your %@ doesn't seem to have any other Apps installed that can open this document." ,
93
+ @" Your %@ doesn't seem to have any other Apps installed that can open this document." ), deviceType];
94
+
95
+ // Display alert
96
+ UIAlertView *alert = [[UIAlertView alloc ] initWithTitle: NSLocalizedString(@" No suitable Apps installed" , @" No suitable App installed" )
97
+ message: message
98
+ delegate: nil
99
+ cancelButtonTitle: NSLocalizedString(@" OK" , @" OK" )
100
+ otherButtonTitles: nil ];
101
+ [alert show ];
102
+ return NO ;
103
+ }
104
+ } else {
105
+ return NO ;
106
+ }
107
+
108
+ return YES ;
109
+ }
110
+
75
111
#pragma mark -
76
112
#pragma mark Document Interaction Controller Delegate Methods
77
113
- (UIViewController *) documentInteractionControllerViewControllerForPreview : (UIDocumentInteractionController *) controller {
0 commit comments