if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *sms_message_vc = [[MFMessageComposeViewController alloc] init];
sms_message_vc.body = text;
sms_message_vc.recipients = recipients;
sms_message_vc.messageComposeDelegate = self;
[self presentModalViewController:sms_message_vc animated:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:TRUE];
[sms_message_vc release];
}
When this executes there's a delay of several seconds before the compose view is actually shown. What is causing this and how does one go about eliminating the delay?
EDIT 1: Clarification: Making sms_message_vc
and ivar doesn't help because the ...alloc] init]
process will hang the UI for seconds, regardless of where it is.
EDIT 2: Tried GCD (with different priorities) to attempt to run initialization concurrently. Did not help:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, (unsigned long)NULL), ^(void){
sms_message_vc = [[MFMessageComposeViewController alloc] init];
sms_message_vc.messageComposeDelegate = self;
});
Consider making MFMessageComposeViewController *sms_message_vc a class instance variable and calling:
earlier, along with setting the delegate to
self
right after initingsms_message_vc
Then just do:
When you want to actually send the message. This shouldn't change it too much but might help some.
I have the same problem. I tried to cache the controller in a static variable. But it did not work. behaved erratically. First time works, second time delegate called automatically without any user action and 3rd time screen goes black. Looks like you have to create the instance after each dismiss!
import Foundation import UIKit import MessageUI
}
usage,