Skip to content

Commit

Permalink
fix(ios): show alert in background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Trusevich committed Dec 3, 2021
1 parent bcc7ac4 commit bf68a9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-sms-plugin",
"version": "1.0.1",
"version": "1.0.1-dev-1.0",
"description": "Cross-platform plugin for Cordova / PhoneGap to to easily send SMS. Available for Android, iOS and WP.",
"cordova": {
"id": "cordova-sms-plugin",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-sms-plugin"
version="1.0.1">
version="1.0.1-dev-1.0">
<name>Cordova SMS Plugin</name>
<description>Cross-platform plugin for Cordova / PhoneGap to to easily send SMS. Available for Android and iOS.</description>
<license>MIT</license>
Expand Down
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 bf68a9e

Please sign in to comment.