rs2000
rs2000

Reputation: 147

strange behaviour from Mail and Message controller - pre initialised

I have pre allocated the mail and messaging controllers on startup in my app delegate to save the initialisation time (over 10 secs) when the user is using my application...

__mailController = [[MFMailComposeViewController alloc] init];
__messageController = [[MFMessageComposeViewController alloc] init];

It works fine the first time the controller is displayed then the next time the message is not changed and the old message is still displayed ?? ... Is it likely that the controller is being deallocated ??? Strange as the views work correctly just that the message is not correct ?

- (IBAction)actionSMS:(id)sender {

if([MFMessageComposeViewController canSendText])
{
    self.messageController.body = self.MessageDetail.text;
//      controller.recipients = [NSArray arrayWithObjects:@"+919999999999", nil];
    [self presentModalViewController:self.messageController animated:YES];
}
}

Upvotes: 0

Views: 302

Answers (2)

Yonat
Yonat

Reputation: 4608

I had the same problem. Not only are the MF controllers only good for one time use, as you discovered, they also cannot be init-ed in the background because their UI elements need to be init-ed in the main thread.

In the end, I just present a UIActivityIndicatorView over a HUD, so the users will know the app is responding.

Upvotes: 0

Matthias Bauch
Matthias Bauch

Reputation: 90117

Once MFMailComposeViewController and MFMessageComposeViewController are presented to the user you can't make changes to the content they display.

MFMailComposeViewController Class Reference:

Important The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.

That means those values are somehow locked in the implementation of the MFM*ViewController at the moment you present the controller. So you can't reuse these viewControllers. iOS doesn't care if the controller is, like in your case, invisible or not. If it is presented the content is locked.

I would figure out why it takes 10 seconds to allocate them. And then dump that whole pre-allocation thingie. 10 seconds are definitely to much.

Upvotes: 1

Related Questions