MFMessageComposeViewController shows blank white screen issue

by

We use an MFMessageComposeViewController object to display the standard message composition interface in order to send text messages in our app. Properties of MFMessageComposeViewController lets us populate pre-defined recipients and body message before presenting the interface.

Simple code to create and present MFMessageComposeViewController is:

            
if([MFMessageComposeViewController canSendText]){
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate = self;
    picker.recipients =@[“1234”];
    picker.body = @“pre-defined message”;
    [self presentViewController:picker animated:YES completion:nil];
}
else{
    NSLog(@“Cannot send text”);
}
            
            
            
if MFMessageComposeViewController.canSendText() {
    let picker = MFMessageComposeViewController()
    picker.messageComposeDelegate = self;
    picker.recipients =[“1234”];
    picker.body = “pre-defined message”;
    self.present(picker, animated: true, completion: nil)
}
else{
    print(“Cannot send text”);
}
            
            

Not so distant, I had stumbled upon a very silly mistake that caused an MFMessageComposeViewController to show blank after presenting.

In this case controller opens up blank and immediately dismisses itself. It was very weird because first thing I thought was maybe If I am dismissing MFMessageComposeViewController after presenting. That was not the case. With the help of breakpoint I did notice that didFinishWithResult delegate method was being called too. This was really weird pattern because according to official documentation:

messageComposeViewController(:didFinishWith:)
The message compose view controller is not dismissed automatically. When the user taps the buttons to send the message or cancel the interface, the message compose view controller calls the messageComposeViewController(
:didFinishWith:) method of its delegate.

You might also like: Sort an array of string containing numbers

As it happens I was just looking at wrong place for a time until I looked at my initialisation code again and I investigated the value of each variables and members of object. It was my silly mistake where I assigned wrong object to recipients. I assigned array of array instead of array of strings. I rectified my mistake and MFMessageComposeViewController did present in proper manner.

Conclusion, my mistake was not assigning array of string to recipients.

You might also like: AVAudioPlayer not playing any sound

You might also like: Blurry Pixel Font in SpriteKit bug

More Articles

Recommended posts