Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank screen after share content using UIActivityViewController

I share some contents using the following code

var textToShare = "Test"
let activityVC = UIActivityViewController(activityItems: [textToShare], applicationActivities: nil)
activityVC.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact]

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

But when I press the cancel button or when the content is shared successfully, the App shows a blank screen.

How to fix this issue ?

UPDATE:

The blank screen just appears when I select mail or sms apps for the sharing target, For Telegram, Twitter and Facebook it is working perfect.

I commented all the code inside lifecycle methods, Still same issue.

override func viewDidAppear(animated: Bool)
{
    //setControlsAreHidden(true)
}

override func viewWillAppear(animated: Bool)
{
    //if dataAddedToView
    //{
    //     activityIndicator?.removeFromSuperview()
    //}

}

override func viewWillDisappear(animated: Bool)
{
    //setControlsAreHidden(false)
}
like image 949
Morteza Soleimani Avatar asked Aug 18 '15 06:08

Morteza Soleimani


3 Answers

I was having this same problem, and was able to solve it by adjust the sizing constraints of my primary UIView.

Code before:

override func loadView() {
    self.view                                           = UIView()
    self.view.translatesAutoresizingMaskIntoConstraints = false
}

Code after:

override func loadView() {
    self.view                                           = UIView()
}

So just remove self.view.translatesAutoresizingMaskIntoConstraints = false

This might not apply to everyone, but based on other peoples' answers, I gather there are various issues with how views are displayed which can cause the same problem. If my fix doesn't work for you, I suggest commenting out all unnecessary code until the problem goes away, and then methodically bring small bits back online, testing along the way to identify your issue.

like image 192
Dave Blue Avatar answered Oct 17 '22 17:10

Dave Blue


As you are presenting MFMailComposeViewController and MFMessageComposeViewController above your current UIViewController so when you dismiss the MFMailComposeViewController or MFMessageComposeViewController after sending the message then your UIViewController viewWillAppear method will be called as the view is appearing again, so in my opinion check in viewWillAppear or viewWillDisappear method whether you are making your view nil.

like image 2
Rajat Avatar answered Oct 17 '22 15:10

Rajat


I don't see any calls to the super implementation in your viewDidAppear, viewWillAppear or viewWillDisappear methods.

What happens if you do?:

override func viewDidAppear(animated: Bool)
{
    super.viewDidAppear(animated)
    //setControlsAreHidden(true)
}

override func viewWillAppear(animated: Bool)
{
    super.viewWillAppear(animated)
    //if dataAddedToView
    //{
    //     activityIndicator?.removeFromSuperview()
    //}

}

override func viewWillDisappear(animated: Bool)
{
    super.viewWillDisappear(animated)
    //setControlsAreHidden(false)
}
like image 1
fdiaz Avatar answered Oct 17 '22 16:10

fdiaz