I am trying to share a URL using UIActivityViewController
as shown below. This presents fine, but cannot be cancelled, i.e. tapping the cancel button does nothing. This is only within my app. If I create a test app with a view controller embedded in a navigation controller it works fine. My app has a tab bar controller with navigation controllers and the view controller I am trying to present this from is on the third tab and is the current top view controller.
NSString *string = @"Check this site out";
NSURL *URL = [NSURL URLWithString:@"www.apple.com"];
self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[string, URL] applicationActivities:nil];
[self.navigationController presentViewController:self.activityViewController animated:YES completion:nil];
I have also tried changing the controller that it is presented from to the tab bar controller and the root view controller of the keyWindow with no luck.
I even tried adding a completion handler as shown below but this does not even get called!
__weak typeof(self) weakSelf = self;
[self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
[weakSelf dismissViewControllerAnimated:YES completion:nil];
}];
Not sure how to proceed...any suggestions welcome.
UPDATE:
Interestingly I have discovered that I cannot cancel/dismiss a UIAlertController either... even with this basic Apple example.
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"This is an alert." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];