Search code examples
iosswiftuiactivityviewcontrolleruiactivityios-sharesheet

Force dismiss iOS share sheet manually Swift iOS 8 and 9


I am using UIActivityViewController to display options. Then select Twitter or Facebook, it appears iOS share sheet.

Is there any way to dismiss share sheet manually? I cant see any delegate to this.

Here is my code:

let arrObjectsToShare = [self, finalTextToShare, secondActivityItem]

let activityVC = UIActivityViewController(activityItems: arrObjectsToShare, applicationActivities: nil)
activityVC.excludedActivityTypes = [
                    UIActivityTypePostToWeibo,....etc]

activityVC.completionWithItemsHandler = {(activityType: String?, bool: Bool, dictType: [AnyObject]?, error: NSError?) -> Void in
    print(activityType)
    }

self.presentViewController(activityVC, animated: true, completion: nil)

Mention: When iOS share sheet is up to screen, keyboard is shown also. I tried to dismiss keyboard, at least, But no way:

self.view.endEditing(true)

Really need help with this. Thanks

UPDATE1 - Screenshots added This is <code>UIActivityViewController</code> This is <code>iOS share sheet</code> or <code>com.apple.UIKit.activity.PostToTwitter</code>  or <code>plugin com.apple.share.Twitter.post</code>


Solution

  • If iOS Share Sheet is displayed, and call this method: self.dismissViewControllerAnimated(true, completion: nil) share sheet is dismissed successfully.