I have also faced the same problem, here is my solution, how i have handled.
NSArray *dataToShare= @[@"Test",@"",[self contentURLofCurrentPreviewItem]];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:nil];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:activityViewController animated:YES completion:nil];
}
else {
// Change Rect to position Popover
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
activityViewController.popoverPresentationController.sourceView = view;
[popup presentPopoverFromRect:view.frame
inView:view.superview
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusNotDetermined)
{
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status)
{
if (status == PHAuthorizationStatusDenied) {
[self showAlert];
}
}];
}
[activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError)
{
if ([activityType isEqualToString:@"com.apple.UIKit.activity.SaveToCameraRoll"])
{
if (![self getaccess])
{
[self showAlert];
}
}
}];
}
}
}
// check access of Photo Library
-(bool)getaccess
{
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusAuthorized)
{
return YES;
// Access has been granted.
}
else if (status == PHAuthorizationStatusDenied) {
return NO;
// Access has been denied.
}
else if (status == PHAuthorizationStatusRestricted)
{
return NO;
// Restricted access - normally won't happen.
}
return NO;
}
-(void)showAlert
{
NSString *message = @"Save Image option required access of Photo Library. Please allow Photos app access for Your App in the Settings application.";
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"Your App", nil)
message:NSLocalizedString(message,nil)
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Go To Settings", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
[alert addAction:settingsAction];
UIAlertAction *Cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
//do something when click button
}];
[alert addAction:Cancel];
[self presentViewController:alert animated:YES completion:nil];
}
}