diff --git a/SharedSources/VLCActivityViewControllerVendor.m b/SharedSources/VLCActivityViewControllerVendor.m index 5f540beb8ea7468687ade381c4ef83a32200ded4..4f6ef6ec6bfe56ca629de33a4abc6e9f31d90fcd 100644 --- a/SharedSources/VLCActivityViewControllerVendor.m +++ b/SharedSources/VLCActivityViewControllerVendor.m @@ -12,7 +12,7 @@ #import "VLCActivityViewControllerVendor.h" #import "VLCOpeninActivity.h" -#import +#import @implementation VLCActivityViewControllerVendor @@ -31,13 +31,24 @@ UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:files applicationActivities:@[openInActivity]]; - controller.completionHandler = ^(NSString *activityType, BOOL completed) { + NSMutableArray *excludedActivities = [@[ + UIActivityTypePrint, + UIActivityTypeAssignToContact, + UIActivityTypeAddToReadingList, + UIActivityTypeOpenInIBooks + ] mutableCopy]; + + if (@available(iOS 11_0, *)) { + [excludedActivities addObject:UIActivityTypeMarkupAsPDF]; + } + controller.excludedActivityTypes = excludedActivities; + controller.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) { APLog(@"UIActivityViewController finished with activity type: %@, completed: %i", activityType, completed); // Provide feedback. This could cause a false positive if the user chose "Don't Allow" in the permissions dialog, and UIActivityViewController does not inform us of that, so check the authorization status. // By the time this is called, the user has not had time to choose whether to allow access to the Photos library, so only display the message if we are truly sure we got authorization. The first time the user saves to the camera roll he won't see the confirmation because of this timing issue. This is better than showing a success message when the user had denied access. A timing workaround could be developed if needed through UIApplicationDidBecomeActiveNotification (to know when the security alert view was dismissed) or through other ALAssets APIs. - if (completed && [activityType isEqualToString:UIActivityTypeSaveToCameraRoll] && [ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) { + if (completed && [activityType isEqualToString:UIActivityTypeSaveToCameraRoll] && [PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized) { [viewController vlc_showAlertWithTitle:NSLocalizedString(@"SHARING_SUCCESS_CAMERA_ROLL", nil) message:nil buttonTitle:NSLocalizedString(@"BUTTON_OK", nil)]; diff --git a/Sources/VLCOpenInActivity.m b/Sources/VLCOpenInActivity.m index 25c3d63de5decb3b4c69fa2255f2d308a8a532a2..577fa45035f9f9c7a7ee8144dd58a9c9a78bcd97 100644 --- a/Sources/VLCOpenInActivity.m +++ b/Sources/VLCOpenInActivity.m @@ -2,10 +2,11 @@ * VLCOpenInActivity.m * VLC for iOS ***************************************************************************** - * Copyright (c) 2014 VideoLAN. All rights reserved. + * Copyright (c) 2017 VideoLAN. All rights reserved. * $Id$ * * Authors: Marc Etcheverry + * Carola Nitz * * Refer to the COPYING file of the official project for license. *****************************************************************************/ @@ -14,7 +15,7 @@ #import -@interface VLCOpenInActivity () +@interface VLCOpenInActivity () @end @implementation VLCOpenInActivity @@ -25,11 +26,6 @@ #pragma mark - UIActivity -- (void)dealloc -{ - _documentInteractionController.delegate = nil; -} - + (UIActivityCategory)activityCategory { return UIActivityCategoryAction; @@ -83,7 +79,7 @@ NSUInteger count = [_fileURLs count]; if (count > 1) { - [self presentFileSelectionActionSheet]; + [self presentFileSelectionActionController]; } else if (count == 1) { [self presentDocumentInteractionControllerWithFileURL:[_fileURLs firstObject]]; } else { @@ -153,40 +149,33 @@ - (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller { [self activityDidFinish:YES]; - _documentInteractionController.delegate = nil; _documentInteractionController = nil; } -#pragma mark - UIActionSheet +#pragma mark - UIAlertController -- (void)presentFileSelectionActionSheet +- (void)presentFileSelectionActionController { - [self.presentingViewController dismissViewControllerAnimated:YES completion:^{ - UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"SHARING_ACTION_SHEET_TITLE_CHOOSE_FILE", nil) - delegate:self - cancelButtonTitle:nil - destructiveButtonTitle:nil - otherButtonTitles:nil]; - - for (NSURL *fileURL in _fileURLs) { - [actionSheet addButtonWithTitle:[fileURL lastPathComponent]]; - } - - actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)]; - - [actionSheet showFromBarButtonItem:self.presentingBarButtonItem animated:YES]; - }]; -} - -#pragma mark - UIActionSheetDelegate - -- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex -{ - if (actionSheet.cancelButtonIndex != buttonIndex) { - [self presentDocumentInteractionControllerWithFileURL:_fileURLs[buttonIndex]]; - } else { - [self activityDidFinish:NO]; + UIAlertController *actionController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"SHARING_ACTION_SHEET_TITLE_CHOOSE_FILE", nil) + message:nil + preferredStyle:UIAlertControllerStyleActionSheet]; + + + for (NSURL *fileURL in _fileURLs) { + UIAlertAction *action = [UIAlertAction actionWithTitle:[fileURL lastPathComponent] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + [self presentDocumentInteractionControllerWithFileURL:fileURL]; + }]; + [actionController addAction:action]; } + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"BUTTON_CANCEL", nil) + style:UIAlertActionStyleCancel + handler:^(UIAlertAction * _Nonnull action) { + [self activityDidFinish:NO]; + }]; + [actionController addAction:cancelAction]; + [self.presentingViewController presentViewController:actionController animated:YES completion:nil]; } @end