From bf68a9e03e215fc65db8e2c53dc22b5f7d2e3d93 Mon Sep 17 00:00:00 2001 From: Eugene Trusevich Date: Fri, 3 Dec 2021 10:29:56 +0300 Subject: [PATCH] fix(ios): show alert in background thread --- package.json | 2 +- plugin.xml | 2 +- src/ios/Sms.m | 33 +++++++++++++++++++-------------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 2115ae7..a45945f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/plugin.xml b/plugin.xml index eb282b4..254ea5e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.1-dev-1.0"> Cordova SMS Plugin Cross-platform plugin for Cordova / PhoneGap to to easily send SMS. Available for Android and iOS. MIT diff --git a/src/ios/Sms.m b/src/ios/Sms.m index 202cb8a..fc245dc 100644 --- a/src/ios/Sms.m +++ b/src/ios/Sms.m @@ -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(), ^{