Skip to content

Commit

Permalink
Merge pull request #226 from expcapitaldev/1.0.1-dev-1.0
Browse files Browse the repository at this point in the history
fix(ios): show alert in background thread with native crash
  • Loading branch information
dbaq authored Jan 12, 2022
2 parents bcc7ac4 + a579f8f commit d4e5ca8
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/ios/Sms.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ - (void)send:(CDVInvokedUrlCommand*)command {
self.callbackID = command.callbackId;

if(![MFMessageComposeViewController canSendText]) {
NSString *errorMessage = @"SMS Text not available.";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notice"
message:errorMessage
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil
];

dispatch_async(dispatch_get_main_queue(), ^{
[alert show];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsString:errorMessage];
dispatch_async(dispatch_get_main_queue(), ^{
NSString *errorMessage = NSLocalizedString(@"SMS Text not available.", nil);

[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackID];
});
return;
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]
message:errorMessage
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *ok =[
UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action){
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMessage];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackID];
}
];
[alert addAction:ok];
[self.viewController presentViewController:alert animated:YES completion:nil];
});
return;
}

dispatch_async(dispatch_get_main_queue(), ^{
Expand Down

0 comments on commit d4e5ca8

Please sign in to comment.