You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by jc...@apache.org on 2020/07/02 10:59:21 UTC
[cordova-plugin-dialogs] branch master updated: breaking(ios):
remove CDVAlertView (#138)
This is an automated email from the ASF dual-hosted git repository.
jcesarmobile pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-dialogs.git
The following commit(s) were added to refs/heads/master by this push:
new 40465ff breaking(ios): remove CDVAlertView (#138)
40465ff is described below
commit 40465ff002e0e0784d7b323951ac15bfbdf9469c
Author: jcesarmobile <jc...@gmail.com>
AuthorDate: Thu Jul 2 12:59:14 2020 +0200
breaking(ios): remove CDVAlertView (#138)
Co-authored-by: Tim Brust <ra...@gmx.de>
---
src/ios/CDVNotification.h | 5 --
src/ios/CDVNotification.m | 158 ++++++++++------------------------------------
2 files changed, 35 insertions(+), 128 deletions(-)
diff --git a/src/ios/CDVNotification.h b/src/ios/CDVNotification.h
index 9253f6a..df06c72 100644
--- a/src/ios/CDVNotification.h
+++ b/src/ios/CDVNotification.h
@@ -30,8 +30,3 @@
- (void)beep:(CDVInvokedUrlCommand*)command;
@end
-
-@interface CDVAlertView : UIAlertView {}
-@property (nonatomic, copy) NSString* callbackId;
-
-@end
diff --git a/src/ios/CDVNotification.m b/src/ios/CDVNotification.m
index 9c775a7..92001a0 100644
--- a/src/ios/CDVNotification.m
+++ b/src/ios/CDVNotification.m
@@ -39,100 +39,50 @@ static NSMutableArray *alertList = nil;
*/
- (void)showDialogWithMessage:(NSString*)message title:(NSString*)title buttons:(NSArray*)buttons defaultText:(NSString*)defaultText callbackId:(NSString*)callbackId dialogType:(NSString*)dialogType
{
-
int count = (int)[buttons count];
-#ifdef __IPHONE_8_0
- if (NSClassFromString(@"UIAlertController")) {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
-
- if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.3) {
-
- CGRect alertFrame = [UIScreen mainScreen].applicationFrame;
-
- if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
- // swap the values for the app frame since it is now in landscape
- CGFloat temp = alertFrame.size.width;
- alertFrame.size.width = alertFrame.size.height;
- alertFrame.size.height = temp;
- }
-
- alertController.view.frame = alertFrame;
- }
- __weak CDVNotification* weakNotif = self;
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
- for (int n = 0; n < count; n++) {
- [alertController addAction:[UIAlertAction actionWithTitle:[buttons objectAtIndex:n]
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * action)
- {
- CDVPluginResult* result;
+ __weak CDVNotification* weakNotif = self;
- if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT])
- {
- NSString* value0 = [[alertController.textFields objectAtIndex:0] text];
- NSDictionary* info = @{
- @"buttonIndex":@(n + 1),
- @"input1":(value0 ? value0 : [NSNull null])
- };
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info];
- }
- else
- {
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(int)(n + 1)];
- }
+ for (int n = 0; n < count; n++) {
+ [alertController addAction:[UIAlertAction actionWithTitle:[buttons objectAtIndex:n]
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction * action)
+ {
+ CDVPluginResult* result;
- [weakNotif.commandDelegate sendPluginResult:result callbackId:callbackId];
- }]];
- }
-
- if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {
-
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.text = defaultText;
- }];
- }
-
- if(!alertList)
- alertList = [[NSMutableArray alloc] init];
- [alertList addObject:alertController];
-
- if ([alertList count]==1) {
- [self presentAlertcontroller];
- }
-
- }
- else
- {
-#endif
+ if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT])
+ {
+ NSString* value0 = [[alertController.textFields objectAtIndex:0] text];
+ NSDictionary* info = @{
+ @"buttonIndex":@(n + 1),
+ @"input1":(value0 ? value0 : [NSNull null])
+ };
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info];
+ }
+ else
+ {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(int)(n + 1)];
+ }
- CDVAlertView* alertView = [[CDVAlertView alloc]
- initWithTitle:title
- message:message
- delegate:self
- cancelButtonTitle:nil
- otherButtonTitles:nil];
-
- alertView.callbackId = callbackId;
-
-
-
- for (int n = 0; n < count; n++) {
- [alertView addButtonWithTitle:[buttons objectAtIndex:n]];
- }
+ [weakNotif.commandDelegate sendPluginResult:result callbackId:callbackId];
+ }]];
+ }
+ if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {
- if ([dialogType isEqualToString:DIALOG_TYPE_PROMPT]) {
- alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
- UITextField* textField = [alertView textFieldAtIndex:0];
+ [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.text = defaultText;
- }
-
- [alertView show];
-#ifdef __IPHONE_8_0
+ }];
+ }
+ if (!alertList) {
+ alertList = [[NSMutableArray alloc] init];
+ }
+ [alertList addObject:alertController];
+
+ if ([alertList count] == 1) {
+ [self presentAlertcontroller];
}
-#endif
-
}
- (void)alert:(CDVInvokedUrlCommand*)command
@@ -166,38 +116,6 @@ static NSMutableArray *alertList = nil;
[self showDialogWithMessage:message title:title buttons:buttons defaultText:defaultText callbackId:callbackId dialogType:DIALOG_TYPE_PROMPT];
}
-/**
- * Callback invoked when an alert dialog's buttons are clicked.
- */
-- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
-{
- CDVAlertView* cdvAlertView = (CDVAlertView*)alertView;
- CDVPluginResult* result;
-
- // Determine what gets returned to JS based on the alert view type.
- if (alertView.alertViewStyle == UIAlertViewStyleDefault) {
- // For alert and confirm, return button index as int back to JS.
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(int)(buttonIndex + 1)];
- } else {
- // For prompt, return button index and input text back to JS.
- NSString* value0 = [[alertView textFieldAtIndex:0] text];
- NSDictionary* info = @{
- @"buttonIndex":@(buttonIndex + 1),
- @"input1":(value0 ? value0 : [NSNull null])
- };
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:info];
- }
- [self.commandDelegate sendPluginResult:result callbackId:cdvAlertView.callbackId];
-}
-
-- (void)didPresentAlertView:(UIAlertView*)alertView
-{
- //show keyboard on iOS 8
- if (alertView.alertViewStyle == UIAlertViewStylePlainTextInput){
- [[alertView textFieldAtIndex:0] selectAll:nil];
- }
-}
-
static void playBeep(int count) {
SystemSoundID completeSound;
NSInteger cbDataCount = count;
@@ -253,9 +171,3 @@ static void soundCompletionCallback(SystemSoundID ssid, void* data) {
}
@end
-
-@implementation CDVAlertView
-
-@synthesize callbackId;
-
-@end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org