iOS 13 UIActivityViewController automatically present previous VC after image saving

uiactivityviewcontroller email recipients
uiactivityviewcontroller share file
uiactivityviewcontroller whatsapp image and text
uiactivityviewcontroller not showing apps
uiactivityviewcontroller email subject
uiactivityviewcontroller preview image
uiactivityviewcontroller share video

I'm trying to implement "Save image to Library" function and then return back to the current view controller, but on a new iOS 13 it dismisses back to the view controller that presented the current one:

PHPhotoLibrary.requestAuthorization({(_ status: PHAuthorizationStatus) -> Void in })

let shareItems: Array = [newImg,"Hello"] as [Any]

let activityController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)

if UIDevice.current.userInterfaceIdiom == .pad {
    activityController.popoverPresentationController?.sourceView = saveButton

present(activityController, animated: true)

I can confirm that this bug is still present in iOS 13.3.1. The following workaround is a Swift version of franze's solution. I prefer this approach, as it doesn't make any further assumptions on the view controller hierarchy and doesn't use method swizzling.

Using this additional UIWindow breaks the Cancel button of the UIActivityViewController on iOS 12 and earlier, so I added a check for the OS version.

private let activityWindow: UIWindow = {
  let window = UIWindow(frame: UIScreen.main.bounds)
  window.rootViewController = UIViewController()
  return window

func showActivityController() {
  let activityViewController = UIActivityViewController(/* ... */)
  activityViewController.completionWithItemsHandler = {
     // ...

  // Use this workaround only on iOS 13
  if ProcessInfo.processInfo.operatingSystemVersion.majorVersion == 13 {
    activityWindow.rootViewController?.present(activityViewController, animated: true)
  } else {
    present(activityViewController, animated: true)

Update: Apparently, this solution doesn't work reliably on iPads. It looks like on iPad the UIActivityViewController is presented differently and as soon as it's visible on screen, no touch events are registered, effectively freezing the app.

iOS 13 UIActivityViewController au…, iOS 13 UIActivityViewController automatically present previous VC after image saving. I'm trying to implement “Save image to Library” function and then return  ANNotunzdY. Mobile Apps and Web developer in Japan. 4 iOS 13 UIActivityViewController automatically present previous VC after image saving Oct 3 '19.

Swift version of @KDP's solution:

let fakeViewController = TransparentViewController()
fakeViewController.modalPresentationStyle = .overFullScreen

activityViewController.completionWithItemsHandler = { [weak fakeViewController] _, _, _, _ in
    if let presentingViewController = fakeViewController?.presentingViewController {
        presentingViewController.dismiss(animated: false, completion: nil)
    } else {
        fakeViewController?.dismiss(animated: false, completion: nil)
present(fakeViewController, animated: true) { [weak fakeViewController] in
    fakeViewController?.present(activityViewController, animated: true, completion: nil)

fakeViewController gets either dismissed by activity completion, or we need to dismiss it in completion.

UIActivityViewController by example – Hacking with Swift, This class, UIActivityViewController , can handle sharing text, URLs, items, applicationActivities: nil) present(ac, animated: true) However, the default share sheet for images will offer users the chance to save the image to their photo Following the steps above to add a subject to shared data, we can  The iOS 12 backward compatibility of iOS 13 for the Xcode 10 build results in a full screen presentation. The style of grouped table views has changed in iOS 13 to hide the space above the first

I generated following monkey patch (Checked by iOS 13.1.2)

- (void)export {

  // ... Generate Your Activity Items ...

  UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                                                                                   completeBlock:^(NSError *activityError, BOOL completed) {
                                                                                                       // Swizzling Dismiss Method
                                                                                                       [[self class]   switchInstanceMethodFrom:@selector(dismissViewControllerAnimated:completion:) To:@selector(lockedDismissViewControllerAnimated:completion:)];
  // Swizzling Dismiss Method
  [[self class] switchInstanceMethodFrom:@selector(dismissViewControllerAnimated:completion:) To:@selector(lockedDismissViewControllerAnimated:completion:)];
  [self presentViewController:activityViewController animated:YES completion:nil];

- (void)lockedDismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
    if ([self presentedViewController]) {
        [self lockedDismissViewControllerAnimated:flag completion:completion];

// from
+(void)switchInstanceMethodFrom:(SEL)from To:(SEL)to
    Method fromMethod = class_getInstanceMethod(self,from);
    Method toMethod   = class_getInstanceMethod(self,to  );
    method_exchangeImplementations(fromMethod, toMethod);

UIActivityViewController explained, Sharing things using iOS uses a standard, powerful component that other apps can As we're working with images, UIActivityViewController will automatically give us and by Twitter and Facebook, as well as saving the image to the photo library, A lot of that code is old; we already learned about present() in project 2. iOS provides a unified interface for users to share and perform actions on strings, images, URLs, and other items within an app. UIActivity View Controller Written by Mattt December 5 th , 2018 ( revised )

Here is the way I worked around this bug for now. I create a fake view controller and push it onto the current stack. It seems that UIActivityTypeSaveToCameraRoll dismisses the top view controller on the stack, whereas the other options do not. I take care of dismissing the fake view controller in the completion block if the activity type is not complete and UIActivityTypeSaveToCameraRoll.

typeof(self) __weak weakSelf = self;

[self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
        if (activityType== UIActivityTypeSaveToCameraRoll && completed){
              weakSelf.activityViewController = nil;
             [weakSelf dismissViewControllerAnimated:NO completion:nil];
             weakSelf.activityViewController = nil;       

UIViewController *fakeVC=[[UIViewController alloc] init];

[self presentViewController:fakeVC animated:NO completion:^{
       [fakeVC presentViewController:self.activityViewController animated:YES completion:nil];

Solution Force Close When Save Image in UIActivityViewController , After saving image the current view controller will dismiss. And it's a How can this bug didn't happened on iOS 12 but happed on iOS 13. fakeViewController​?.present(activityViewController, animated: true, completion: nil). Questions: In iOS 8, it seems that buttons on UIAlertController (specifically the action sheet type) as well as buttons on the UIActivityViewController get their color from the main window’s tintColor.

- (UIWindow *)displayWindow
    if (!_displayWindow)
        _displayWindow = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
        _displayWindow.rootViewController = [[UIViewController alloc] init];
    return _displayWindow;

- (void)showActivityController
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[] applicationActivities:nil];
    activityViewController.completionWithItemsHandler = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError)
        [UIApplication.sharedApplication.delegate.window makeKeyAndVisible];

    [self.displayWindow makeKeyAndVisible];
    [self.displayWindow.rootViewController presentViewController:activityViewController animated:true completion:nil];

Make sure the _displayWindow is strong reference.

Faster UIActivityViewController Share Sheets with , A common annoyance using iOS share sheets that just opening them will lock up And I'm sure the blame falls to a previous misinterpretation that you need to self.present(activityViewController, animated: true, completion: nil) UIActivityItemProvider will call this after a user selects an activity from the  uiactivityviewcontroller objective c (10) . I am currently testing my app with Xcode 6 (Beta 6). UIActivityViewController works fine with iPhone devices and simulators but crashes with iPad simulators and devices (iOS 8) wit

Uiactivityviewcontroller popoverpresentationcontroller, iOS 13 UIActivityViewController automatically present previous VC after image saving 4671 Views 10 Replies Latest reply on Apr 3, 2020 3:59 AM by alexbuga​  Previously, we covered how to use the built-in APIs to read a RSS feed and build a simple RSS Reader app.In this tutorial, we are going to learn how to use the built-in camera of the iPhone (or the iPod or iPad, if they have one) to take a photo.

Shin. Y on Twitter: "I encountered this bug / iOS 13 , Author of FloatingPanel(iOS). My goal is to create great tools to make iOS 13 UIActivityViewController automatically present previous VC after image saving  Visit our projects site for tons of fun, step-by-step project guides with Raspberry Pi HTML/CSS Python Scratch Blender Our Mission Our mission is to put the power of computing and digital making into the hands of people all over the world.

  • Yes, I can confirm the same problem on iOS 13. I’d suggest you file a bug report.
  • Unrelated but there is no reason for the device check. You can set the sourceView regardless. But you should also set a sourceRect.
  • Interestingly, I notice that the bug only manifests itself if you choose to save the image. If you choose the other options, it appears to return back to the correct view controller.
  • I'm seeing the same issue. This even happens on a device running iOS 13 with an app built with Xcode 10.
  • This is a really good bug!
  • Thank you! Finally solved for my case. I've changed only this line activityViewController.completionWithItemsHandler = { (activity: UIActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) in )}
  • Upon further testing, I noticed that my original solution doesn't work correctly on iOS 12 and earlier - please see my updated answer.
  • Thanks a lot, useful note!
  • @Theo Im assuming that this is implemented into the .m file of the plugin but i am struggling to find where, i have tried bypassing the getTopMostViewController function but it just breaks it could you show where you implemented this to overwrite the standard view. thank you in advance
  • @troggy69 Implement the method in the view controller that presents the UIActivityViewController. Then, instead of calling present(activityViewController, animated: true), call showActivityViewController() instead.
  • I implemented an equivalent solution and it has worked well so far.
  • Can you write the code?
  • Please write the code.