From 0985e76bfb42bbcd61b073b6adb956a55c44e01a Mon Sep 17 00:00:00 2001 From: nasli Date: Wed, 17 Jan 2018 19:08:59 +0100 Subject: [PATCH] Fix to support whitelisted apps in openWith for all iOS versions --- Owncloud iOs Client/AppDelegate.m | 9 +- .../Preview/DetailView/DetailViewController.m | 23 +---- .../Tabs/FileTab/FilesViewController.m | 12 +-- .../Tabs/FileTab/OpenWith/OpenWith.h | 7 -- .../Tabs/FileTab/OpenWith/OpenWith.m | 93 ++----------------- Owncloud iOs Client/Utils/SystemConstants.h | 4 - 6 files changed, 17 insertions(+), 131 deletions(-) diff --git a/Owncloud iOs Client/AppDelegate.m b/Owncloud iOs Client/AppDelegate.m index 5e85a932df..5ca9251af9 100644 --- a/Owncloud iOs Client/AppDelegate.m +++ b/Owncloud iOs Client/AppDelegate.m @@ -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) { diff --git a/Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m b/Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m index db9f59d14c..ffe56afacc 100755 --- a/Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m +++ b/Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m @@ -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]; @@ -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"); @@ -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]; } } diff --git a/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m b/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m index bfbe0d5199..514c00f5ff 100644 --- a/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m +++ b/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m @@ -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) { @@ -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 { diff --git a/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h b/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h index 69b4662782..73799c2299 100644 --- a/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h +++ b/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h @@ -37,13 +37,6 @@ @property(nonatomic,weak) __weak id 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; diff --git a/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m b/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m index 65652a61dc..ea240bc2a2 100644 --- a/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m +++ b/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m @@ -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 diff --git a/Owncloud iOs Client/Utils/SystemConstants.h b/Owncloud iOs Client/Utils/SystemConstants.h index 5cffc93a91..108fcfcbbd 100644 --- a/Owncloud iOs Client/Utils/SystemConstants.h +++ b/Owncloud iOs Client/Utils/SystemConstants.h @@ -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