Commit cb4b1848 authored by Carola Nitz's avatar Carola Nitz

VLCActivityViewControllerVendor: sheet for sharing is now showing again

In presentFileSelectionActionController we first dismissed a presenting controller and in the completion handled the file selection.
Since there was no controller to be dismissed, the completion never got called.
Also replaced some deprecated API while at it and excluded some sharingactivities that included printing.
parent f9867ab3
......@@ -12,7 +12,7 @@
#import "VLCActivityViewControllerVendor.h"
#import "VLCOpeninActivity.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/PHPhotoLibrary.h>
@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)];
......
......@@ -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 <marc # taplightsoftware com>
* Carola Nitz <caro # videolan org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
......@@ -14,7 +15,7 @@
#import <MobileCoreServices/MobileCoreServices.h>
@interface VLCOpenInActivity () <UIActionSheetDelegate, UIDocumentInteractionControllerDelegate>
@interface VLCOpenInActivity () <UIDocumentInteractionControllerDelegate>
@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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment