From 1e81fd70ab50fbf7975550cd1447f0fd6b4aeb53 Mon Sep 17 00:00:00 2001 From: Maihan Nijat Date: Tue, 26 Jan 2021 13:28:42 -0500 Subject: [PATCH] Update Sms.m #218 Wrapped the opening of text composer with `dispatch_async` to fix the main thread issue. --- src/ios/Sms.m | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ios/Sms.m b/src/ios/Sms.m index ae92a0f..202cb8a 100644 --- a/src/ios/Sms.m +++ b/src/ios/Sms.m @@ -26,27 +26,27 @@ - (void)send:(CDVInvokedUrlCommand*)command { return; } - MFMessageComposeViewController *composeViewController = [[MFMessageComposeViewController alloc] init]; - composeViewController.messageComposeDelegate = self; + dispatch_async(dispatch_get_main_queue(), ^{ + MFMessageComposeViewController *composeViewController = [[MFMessageComposeViewController alloc] init]; + composeViewController.messageComposeDelegate = self; - NSString* body = [command.arguments objectAtIndex:1]; - if (body != nil) { - BOOL replaceLineBreaks = [[command.arguments objectAtIndex:3] boolValue]; - if (replaceLineBreaks) { - body = [body stringByReplacingOccurrencesOfString: @"\\n" withString: @"\n"]; + NSString* body = [command.arguments objectAtIndex:1]; + if (body != nil) { + BOOL replaceLineBreaks = [[command.arguments objectAtIndex:3] boolValue]; + if (replaceLineBreaks) { + body = [body stringByReplacingOccurrencesOfString: @"\\n" withString: @"\n"]; + } + [composeViewController setBody:body]; } - [composeViewController setBody:body]; - } - NSMutableArray* recipients = [command.arguments objectAtIndex:0]; - if (recipients != nil) { - if ([recipients.firstObject isEqual: @""]) { - [recipients replaceObjectAtIndex:0 withObject:@"?"]; + NSMutableArray* recipients = [command.arguments objectAtIndex:0]; + if (recipients != nil) { + if ([recipients.firstObject isEqual: @""]) { + [recipients replaceObjectAtIndex:0 withObject:@"?"]; + } + + [composeViewController setRecipients:recipients]; } - - [composeViewController setRecipients:recipients]; - } - dispatch_async(dispatch_get_main_queue(), ^{ [self.viewController presentViewController:composeViewController animated:YES completion:nil]; }); }];