Skip to content

Commit

Permalink
Update Sms.m
Browse files Browse the repository at this point in the history
cordova-sms#218 Wrapped the opening of text composer with `dispatch_async` to fix the main thread issue.
  • Loading branch information
maihannijat authored Jan 26, 2021
1 parent 77e8591 commit 1e81fd7
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/ios/Sms.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
}];
Expand Down

0 comments on commit 1e81fd7

Please sign in to comment.