Skip to content

Commit

Permalink
Fix to support whitelisted apps in openWith for all iOS versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nasli committed Jan 24, 2018
1 parent 75a195a commit 0985e76
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 131 deletions.
9 changes: 2 additions & 7 deletions Owncloud iOs Client/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1765,13 +1765,8 @@ - (void) closeAlertViewAndViewControllers {
if (self.presentFilesViewController){
//Close the openWith option in FileViewController
if (self.presentFilesViewController.openWith) {
if (k_use_open_with_UIDocumentInteractionController) {
[self.presentFilesViewController.openWith.documentInteractionController dismissMenuAnimated:NO];
self.presentFilesViewController.openWith.documentInteractionController = nil;
} else {
[self.presentFilesViewController.openWith.activityView dismissViewControllerAnimated:NO completion:nil];
self.presentFilesViewController.openWith.activityView = nil;
}
[self.presentFilesViewController.openWith.documentInteractionController dismissMenuAnimated:NO];
self.presentFilesViewController.openWith.documentInteractionController = nil;
}
//Close the delete option in FilesViewController
if (self.presentFilesViewController.mDeleteFile.popupQuery) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,11 +845,7 @@ - (void)presentWhiteView {

_titleLabel.text = @"";

if (k_use_open_with_UIDocumentInteractionController) {
[_openWith.documentInteractionController dismissMenuAnimated:YES];
} else {
[_openWith.activityPopoverController dismissPopoverAnimated:YES];
}
[_openWith.documentInteractionController dismissMenuAnimated:YES];

[self removeThePreviousViews];

Expand Down Expand Up @@ -1058,16 +1054,9 @@ - (IBAction)didPressOpenWithButton:(id)sender
*/
- (IBAction)didPressShareLinkButton:(id)sender {
DLog(@"Share button clicked");

if (k_use_open_with_UIDocumentInteractionController) {

if (_openWith && _openWith.documentInteractionController) {
[_openWith.documentInteractionController dismissMenuAnimated:YES];
}
} else {
if (_openWith && _openWith.activityView) {
[_openWith.activityPopoverController dismissPopoverAnimated:YES];
}
if (_openWith && _openWith.documentInteractionController) {
[_openWith.documentInteractionController dismissMenuAnimated:YES];
}

DLog(@"Share Link Option");
Expand Down Expand Up @@ -1747,11 +1736,7 @@ - (void) customWillRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterf

if (_openWith) {

if (k_use_open_with_UIDocumentInteractionController) {
[_openWith.documentInteractionController dismissMenuAnimated:NO];
} else {
[_openWith.activityPopoverController dismissPopoverAnimated:NO];
}
[_openWith.documentInteractionController dismissMenuAnimated:NO];
}

}
Expand Down
12 changes: 2 additions & 10 deletions Owncloud iOs Client/Tabs/FileTab/FilesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,7 @@ - (BOOL)shouldAutorotate {
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

if (self.openWith && !IS_IPHONE) {
if (k_use_open_with_UIDocumentInteractionController) {
[self.openWith.documentInteractionController dismissMenuAnimated:NO];
} else {
[self.openWith.activityView dismissViewControllerAnimated:NO completion:nil];
}
[self.openWith.documentInteractionController dismissMenuAnimated:NO];
}

if (self.plusActionSheet) {
Expand Down Expand Up @@ -2547,11 +2543,7 @@ - (void)didSelectOpenWithOptionAndFile:(FileDto *)file {
if (_selectedIndexPath) {
cell = [_tableView cellForRowAtIndexPath:_selectedIndexPath];
_openWith.parentView =_tableView;
if (k_use_open_with_UIDocumentInteractionController) {
_openWith.cellFrame = [self.tableView rectForRowAtIndexPath:self.selectedIndexPath];
} else {
_openWith.cellFrame = cell.frame;
}
_openWith.cellFrame = [self.tableView rectForRowAtIndexPath:self.selectedIndexPath];
_openWith.isTheParentViewACell = YES;

} else {
Expand Down
7 changes: 0 additions & 7 deletions Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
@property(nonatomic,weak) __weak id<OpenWithDelegate> delegate;
@property(nonatomic, strong) UIView *parentView;
@property(nonatomic, strong) UIDocumentInteractionController *documentInteractionController;

/* Use UIActivityViewController and UIPopoverController instead of UIDocumentInteractionController
* for open with option until fix for UIDocumentInteractionController in iOS11
*/
@property(nonatomic, strong) UIActivityViewController *activityView;
@property (nonatomic, strong) UIPopoverController *activityPopoverController;

@property(nonatomic, strong) UIBarButtonItem *parentButton;
@property(nonatomic, strong) Download *download;
@property(nonatomic, strong) NSString *currentLocalFolder;
Expand Down
93 changes: 9 additions & 84 deletions Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,100 +91,25 @@ - (void)openWithFile: (FileDto *) file{

DLog(@"File path is %@", file.localFolder);

if (k_use_open_with_UIDocumentInteractionController) {

//Pass path to url
NSURL *url = [NSURL fileURLWithPath:file.localFolder];
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
[self.documentInteractionController setDelegate:self];
UIViewController *presentedView = [PresentedViewUtils getPresentedViewControllerInWindow:[[[UIApplication sharedApplication] windows] lastObject]];
//Pass path to url
NSURL *url = [NSURL fileURLWithPath:file.localFolder];
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
[self.documentInteractionController setDelegate:self];

if (_isTheParentViewACell) {

if (_isTheParentViewACell) {

[self.documentInteractionController presentOptionsMenuFromRect:self.cellFrame inView:self.parentView animated:YES];

} else {

if (IS_IPHONE) {
[self.documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:presentedView.view animated:YES];

} else {
[self.documentInteractionController presentOptionsMenuFromBarButtonItem:self.parentButton animated:YES];
}
}
[self.documentInteractionController presentOptionsMenuFromRect:self.cellFrame inView:self.parentView animated:YES];

} else {

AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];

DLog(@"File path is %@", file.localFolder);

//Pass path to url
NSURL *url = [NSURL fileURLWithPath:file.localFolder];

TTOpenInAppActivity *openInAppActivity;

if (_isTheParentViewACell) {
openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:self.parentView andRect:_cellFrame];

}else{
openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:self.parentView andBarButtonItem:self.parentButton];
}


if (self.activityView) {
[self.activityView dismissViewControllerAnimated:YES completion:nil];
self.activityView = nil;
}

if (self.activityPopoverController) {
[self.activityPopoverController dismissPopoverAnimated:YES];
self.activityPopoverController = nil;
}

self.activityView = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:@[openInAppActivity]];

if (IS_IPHONE) {
[self.documentInteractionController presentOptionsMenuFromRect:CGRectZero inView:self.parentView animated:YES];

openInAppActivity.superViewController = self.activityView;

[app.ocTabBarController presentViewController:self.activityView animated:YES completion:nil];
} else {

if (self.activityPopoverController) {
[self.activityPopoverController setContentViewController:self.activityView];
} else {
self.activityPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.activityView];
}

openInAppActivity.superViewController = self.activityPopoverController;

if (_isTheParentViewACell && IS_PORTRAIT) {

[self.activityPopoverController presentPopoverFromRect:CGRectMake(app.detailViewController.view.frame.size.width/2, app.detailViewController.view.frame.size.width/2, 100, 100) inView:app.detailViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}else{

if (_isTheParentViewACell) {
//Present view from cell from file list
[self.activityPopoverController presentPopoverFromRect:_cellFrame inView:_parentView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

} else if (_parentButton) {
//Present view from bar button item
[self.activityPopoverController presentPopoverFromBarButtonItem:_parentButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

} else {
//Present view from rect
[self.activityPopoverController presentPopoverFromRect:CGRectMake(100, 100, 200, 400) inView:_parentView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
}
[self.documentInteractionController presentOptionsMenuFromBarButtonItem:self.parentButton animated:YES];
}


}
}


}

#pragma mark - UIDocumentInteractionControllerDelegate methods
Expand Down
4 changes: 0 additions & 4 deletions Owncloud iOs Client/Utils/SystemConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,3 @@
#define IS_PORTRAIT (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)
#define APP_DELEGATE ((AppDelegate *)[[UIApplication sharedApplication] delegate])
#define IS_IPHONE_PLUS (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

//openWith mode
//only use open with UIDocumentInteraciton with iOS<11 until fix the issue with UIDocumentInteractionController in iOS11
#define k_use_open_with_UIDocumentInteractionController YES

0 comments on commit 0985e76

Please sign in to comment.