MFMessageComposeViewController creates a blank message when 'cancel' is pressed. The message appears in the messaging app without recepient and body.

let controller = MFMessageComposeViewController()

controller.body = "message body"

controller.recipients = mobileNumers ["4547887542154"]

controller.messageComposeDelegate = self

self.present(controller, animated: true, completion: nil)



This present the message composer. But when pressed cancelled the viewcontroller dismiss properly, But this creates a blank message in Messaging app. The message behaves like draft but without recepient and text body. Can anyone help on this?


Help will be highly appreciated.

Thanks:)

I wasn’t able to reproduce the problem you’re seeing. Here’s the entire code for my view controller:

import UIKit
import MessageUI

class MainViewController : UITableViewController, MFMessageComposeViewControllerDelegate {

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let controller = MFMessageComposeViewController()
        controller.body = "message body"
        controller.recipients = ["+1 408 996 1010"]
        controller.messageComposeDelegate = self
        self.present(controller, animated: true, completion: nil)
        self.tableView.deselectRow(at: indexPath, animated: true)
    }

    func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
        self.dismiss(animated: true, completion: nil)
    }
}

When I hit Cancel the message composer goes away. Then, when I switch to Messages, I don’t see any rogue blank messages.

I was testing on iOS 10.3.2.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi,


After a very hard try i got success to reproduce the bug of blank text message.


Please find screen shot for the same. However this issue occurs very very infrequently.


Check out 5th row. the sms is composed however with NO recepient as well as details. It allow you to go details of it, but its blank inside.


Alas, your screen shot did not come through [1]. I recommend that you upload it to some image hosting site and post a URL. That will require moderator approval, but I can take care of that.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] This is not something you did wrong, but rather a limitation of DevForums. I’m still hoping to get it fixed (r. 33172582) but that’s not going to happen soon.

I have a suggestion - its a very remote possibility - but I've had issues with MFMessageComposeViewController in the past. It should be worth a few minutes of your time.


The suggestion is to make MFMessageComposeViewController() an ivar - optional - set it when created so it keeps a strong reference to the object, and only release it (but making the ivar nil) in a block posted to the main thread. More:


- insure that you are on main thread when creating the object: assert(NSThread.isMainThread)

- use an ivar instead of a local variable (or at least save object to the ivar before releasing it)

- in the delegate method, perhaps "print" the type of message you get just to insure nothing else is wrong

- in the delegate, dispatch a block to the main thread that nils our your ivar with the strong reference to MFMessageComposeViewController


Why did I respond? Well, I have a Q&A on StackOverflow about weird crashes with MFMessageComposeViewController - my suggestion there is as above, and that anser got me 50 award points and four upvotes, one that happened this AM :-)

Even i am facing the same issue. White screen pops up, happens only for some devices at random. Client is breathing down my neck. When i tried it on my phone iphone 7 latest OS it worked fine, but today i am testing it and boom white screen. And the app that we have created for our client needs this SMS sending faclity otherwise the users can't register to access the app (its a mobile banking application). Checked eveything the recipients subject everything. Restarted my phone and it worked. Any idea why? Should i put a message in my app saying please restart your iphone if you see a white screen?

Even i am facing the same issue.

This sounds like a very different issue, although it’s hard to be 100% sure without pvn2266’s screen shot.

With regards your issue, it sounds very much like a bug in the OS rather than a problem with your code. The next time you reproduce it, please grab a screen shot and a sysdiagnose log (see the instructions on our Bug Reporting > Profiles and Logs page) and file a bug report

I’d appreciate you posting your bug number, just for the record.

I doubt there’s anything you’ll be able to do to work around this, so release noting this may be your best option )-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
MFMessageComposeViewController creates a blank message when 'cancel' is pressed. The message appears in the messaging app without recepient and body.
 
 
Q