Morteza Soleimani
Morteza Soleimani

Reputation: 2670

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)
}

Upvotes: 10

Views: 1800

Answers (5)

Dave Blue
Dave Blue

Reputation: 141

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.

Upvotes: 2

rholmes
rholmes

Reputation: 4174

You need to first check that your view controller is not being destroyed while you're presenting content. Some debug statements in the presenting view controller's lifecycle management routines (e.g., ViewWillDisappear) could help.

If the problem stems from the ViewController disappearing, you'll need to recreate it appropriately.

Also look at any place where you provide content: is it being triggered to draw at the right times?

Additionally, ensure you're using APIs as required (e.g., calling the superclass in all methods where it's required, such as the view controller lifecycle routines). See:

These are the areas I would focus my attention on and/or provide the relevant code for.

Upvotes: 1

Pablo A.
Pablo A.

Reputation: 2052

Maybe you're not presenting the activity view controller in the proper view, try something like this:

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){
   activityViewController.popoverPresentationController.sourceView = self.view;
}

It's a objective C code, but just as example of how to set the view.

If you need how to check the iOS version:

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

Upvotes: 1

fdiaz
fdiaz

Reputation: 2600

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)
}

Upvotes: 1

Rajat
Rajat

Reputation: 11127

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.

Upvotes: 2

Related Questions