diff --git a/dsBridge.podspec b/dsBridge.podspec index 27d5839..4a403a2 100644 --- a/dsBridge.podspec +++ b/dsBridge.podspec @@ -64,11 +64,11 @@ Pod::Spec.new do |s| # the deployment target. You can optionally include the target after the platform. # - s.platform = :ios, "8.0" + s.platform = :ios, "10.0" # s.platform = :ios, "5.0" # When using multiple platforms - s.ios.deployment_target = "8.0" + s.ios.deployment_target = "10.0" # s.osx.deployment_target = "10.7" # s.watchos.deployment_target = "2.0" # s.tvos.deployment_target = "9.0" diff --git a/dsbridge.xcodeproj/project.pbxproj b/dsbridge.xcodeproj/project.pbxproj index b9da3f3..99b0323 100644 --- a/dsbridge.xcodeproj/project.pbxproj +++ b/dsbridge.xcodeproj/project.pbxproj @@ -461,12 +461,13 @@ DEFINES_MODULE = YES; DEVELOPMENT_TEAM = XTLLEQZMD7; INFOPLIST_FILE = dsbridgedemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = wendu.dsbridgedemo.xx; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "dsbridgedemo/dsbridgedemo-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -479,11 +480,12 @@ DEFINES_MODULE = YES; DEVELOPMENT_TEAM = XTLLEQZMD7; INFOPLIST_FILE = dsbridgedemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = wendu.dsbridgedemo.xx; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "dsbridgedemo/dsbridgedemo-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/dsbridge/DWKWebView.m b/dsbridge/DWKWebView.m index 1bfbbff..c6c25ea 100644 --- a/dsbridge/DWKWebView.m +++ b/dsbridge/DWKWebView.m @@ -10,14 +10,12 @@ @implementation DWKWebView void (^confirmHandler)(BOOL); void (^promptHandler)(NSString *); void(^javascriptCloseWindowListener)(void); - int dialogType; int callId; bool jsDialogBlock; NSMutableDictionary *javaScriptNamespaceInterfaces; NSMutableDictionary *handerMap; NSMutableArray * callInfoList; NSDictionary *dialogTextDic; - UITextField *txtName; UInt64 lastCallTime ; NSString *jsCache; bool isPending; @@ -27,8 +25,6 @@ @implementation DWKWebView -(instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration { - txtName=nil; - dialogType=0; callId=0; alertHandler=nil; confirmHandler=nil; @@ -92,21 +88,27 @@ - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSSt initiatedByFrame:frame completionHandler:completionHandler]; }else{ - dialogType=3; if(jsDialogBlock){ promptHandler=completionHandler; } - UIAlertView *alert = [[UIAlertView alloc] - initWithTitle:prompt - message:@"" - delegate:self - cancelButtonTitle:dialogTextDic[@"promptCancelBtn"]?dialogTextDic[@"promptCancelBtn"]:@"取消" - otherButtonTitles:dialogTextDic[@"promptOkBtn"]?dialogTextDic[@"promptOkBtn"]:@"确定", - nil]; - [alert setAlertViewStyle:UIAlertViewStylePlainTextInput]; - txtName = [alert textFieldAtIndex:0]; - txtName.text=defaultText; - [alert show]; + + UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:prompt message:@"" preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction* sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + UITextField *textFile = alertVC.textFields.firstObject; + self->promptHandler(textFile.text); + self->promptHandler=nil; + }]; + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + self->promptHandler=nil; + }]; + [alertVC addAction:sureAction]; + [alertVC addAction:cancelAction]; + UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; + [keyWindow.rootViewController presentViewController:alertVC animated:YES completion:nil]; + [alertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { + textField.placeholder = @"请输入"; + textField.text = defaultText; + }]; } } } @@ -126,17 +128,24 @@ - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSStrin initiatedByFrame:frame completionHandler:completionHandler]; }else{ - dialogType=1; if(jsDialogBlock){ alertHandler=completionHandler; } - UIAlertView *alertView = - [[UIAlertView alloc] initWithTitle:dialogTextDic[@"alertTitle"]?dialogTextDic[@"alertTitle"]:@"提示" - message:message - delegate:self - cancelButtonTitle:dialogTextDic[@"alertBtn"]?dialogTextDic[@"alertBtn"]:@"确定" - otherButtonTitles:nil,nil]; - [alertView show]; + NSString *aMessage = @""; + if (message != nil) { + aMessage = message; + } else if (dialogTextDic[@"alertTitle"] != nil) { + aMessage = dialogTextDic[@"alertTitle"]; + } + UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:aMessage preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction* sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + self->alertHandler(); + self->alertHandler=nil; + }]; + + [alertVC addAction:sureAction]; + UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; + [keyWindow.rootViewController presentViewController:alertVC animated:YES completion:nil]; } } @@ -153,17 +162,28 @@ -(void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSStri initiatedByFrame:frame completionHandler:completionHandler]; }else{ - dialogType=2; if(jsDialogBlock){ confirmHandler=completionHandler; } - UIAlertView *alertView = - [[UIAlertView alloc] initWithTitle:dialogTextDic[@"confirmTitle"]?dialogTextDic[@"confirmTitle"]:@"提示" - message:message - delegate:self - cancelButtonTitle:dialogTextDic[@"confirmCancelBtn"]?dialogTextDic[@"confirmCancelBtn"]:@"取消" - otherButtonTitles:dialogTextDic[@"confirmOkBtn"]?dialogTextDic[@"confirmOkBtn"]:@"确定", nil]; - [alertView show]; + NSString *aMessage = @""; + if (message != nil) { + aMessage = message; + } else if (dialogTextDic[@"confirmTitle"] != nil) { + aMessage = dialogTextDic[@"confirmTitle"]; + } + UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:aMessage preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction* sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + self->confirmHandler(YES); + self->confirmHandler=nil; + }]; + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + self->confirmHandler(NO); + self->confirmHandler=nil; + }]; + [alertVC addAction:sureAction]; + [alertVC addAction:cancelAction]; + UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; + [keyWindow.rootViewController presentViewController:alertVC animated:YES completion:nil]; } } @@ -211,25 +231,6 @@ - (void)webView:(WKWebView *)webView commitPreviewingViewController:(UIViewContr } } -- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex -{ - if(dialogType==1 && alertHandler){ - alertHandler(); - alertHandler=nil; - }else if(dialogType==2 && confirmHandler){ - confirmHandler(buttonIndex==1?YES:NO); - confirmHandler=nil; - }else if(dialogType==3 && promptHandler && txtName) { - if(buttonIndex==1){ - promptHandler([txtName text]); - }else{ - promptHandler(@""); - } - promptHandler=nil; - txtName=nil; - } -} - - (void) evalJavascript:(int) delay{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{ @synchronized(self){