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]; }); }];