How to fix the delay in the presentation of the MFMessageComposeViewController?

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 is done there, there is a delay of a few seconds until the layout view is actually displayed. What causes this and how is the delay eliminated?

EDIT 1: Clarification: creating sms_message_vcand ivar does not help, because the process ...alloc] init]will hang on the user interface for several seconds, regardless of where it is located.

EDIT 2: Tried GCD (with different priorities) to try to start initialization at the same time. 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; 
});
+5
source share
2 answers

Consider creating an MFMessageComposeViewController * sms_message_vc class instance variable and call:

MFMessageComposeViewController *sms_message_vc = [[MFMessageComposeViewController alloc] init];

, self sms_message_vc

:

sms_message_vc.body = text;
sms_message_vc.recipients = recipients;
[self presentModalViewController:sms_message_vc animated:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:TRUE];
[sms_message_vc release];

. , .

0

. . . . , - , . , !

import Foundation UIKit import MessageUI

class UIUtil {

static var messageController:MFMessageComposeViewController? = nil
static var checkedOnce = false

class func createMessageController () -> MFMessageComposeViewController? {
    if checkedOnce {
        return messageController
    }
    checkedOnce = true
    if (MFMessageComposeViewController.canSendText()) {
        messageController = MFMessageComposeViewController()
        messageController?.recipients = [SettingsManager.shared.switchPhoneNumber]
    } else {
        print("SMS services are not available in this device.")
    }
    return messageController
}

}

func createSMSView (text:String) {
        print("Sending SMS to \(SettingsManager.shared.switchPhoneNumber). Text: \(text)")
        if let ctr = UIUtil.createMessageController() {
            ctr.body = text
            ctr.messageComposeDelegate = self
            self.present(ctr, animated: true, completion: nil)
        } else {
            print("Could not send SMS. Text: \(text)")
        }
    }
0

All Articles