From fe4e90ec53ca6e1d18f17b5bcca5b3a2ad7dd0b6 Mon Sep 17 00:00:00 2001 From: pengfeizhou Date: Mon, 1 Feb 2021 18:10:11 +0800 Subject: [PATCH] iOS:Native plugin use safe method to get from dictionary,avoid type error --- .../Pod/Classes/Plugin/DoricAnimatePlugin.m | 11 ++++--- .../Classes/Plugin/DoricCoordinatorPlugin.m | 18 ++++++----- .../Pod/Classes/Plugin/DoricModalPlugin.m | 32 +++++++++---------- .../Pod/Classes/Plugin/DoricNavBarPlugin.m | 24 +++++++------- .../Pod/Classes/Plugin/DoricNavigatorPlugin.m | 21 ++++-------- .../Pod/Classes/Plugin/DoricNetworkPlugin.m | 13 ++++---- .../Classes/Plugin/DoricNotificationPlugin.m | 14 ++++---- .../Pod/Classes/Plugin/DoricPopoverPlugin.m | 8 ++--- .../Pod/Classes/Plugin/DoricShaderPlugin.m | 13 ++++---- .../Pod/Classes/Plugin/DoricStatusBarPlugin.m | 7 ++-- .../Pod/Classes/Plugin/DoricStoragePlugin.m | 18 ++++++----- 11 files changed, 91 insertions(+), 88 deletions(-) diff --git a/doric-iOS/Pod/Classes/Plugin/DoricAnimatePlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricAnimatePlugin.m index 2c9ad353..f5db7cef 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricAnimatePlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricAnimatePlugin.m @@ -17,8 +17,10 @@ // Created by pengfei.zhou on 2019/11/29. // +#import #import "DoricAnimatePlugin.h" #import "DoricRootNode.h" +#import "DoricExtensions.h" @implementation DoricAnimatePlugin @@ -27,20 +29,21 @@ - (void)submit:(NSDictionary *)args withPromise:(DoricPromise *)promise { } - (void)animateRender:(NSDictionary *)args withPromise:(DoricPromise *)promise { - NSNumber *duration = args[@"duration"]; + NSNumber *duration = [args optNumber:@"duration"]; + NSString *viewId = [args optString:@"id"]; + NSDictionary *props = [args optObject:@"props"]; __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - NSString *viewId = args[@"id"]; [UIView animateWithDuration:[duration floatValue] / 1000 animations:^{ if (self.doricContext.rootNode.viewId == nil) { self.doricContext.rootNode.viewId = viewId; - [self.doricContext.rootNode blend:args[@"props"]]; + [self.doricContext.rootNode blend:props]; [self.doricContext.rootNode requestLayout]; } else { DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; - [viewNode blend:args[@"props"]]; + [viewNode blend:props]; [viewNode requestLayout]; } } diff --git a/doric-iOS/Pod/Classes/Plugin/DoricCoordinatorPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricCoordinatorPlugin.m index 36c82c9f..f6712580 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricCoordinatorPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricCoordinatorPlugin.m @@ -17,11 +17,13 @@ // Created by pengfei.zhou on 2020/2/13. // +#import #import "DoricCoordinatorPlugin.h" #import "DoricSuperNode.h" #import "DoricScrollableProtocol.h" #import "DoricUtil.h" #import "DoricRootNode.h" +#import "DoricExtensions.h" @implementation DoricCoordinatorPlugin @@ -29,7 +31,7 @@ - (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)pro __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - NSArray *scrollableIds = params[@"scrollable"]; + NSArray *scrollableIds = [params optArray:@"scrollable"]; DoricViewNode *scrollNode = nil; for (NSString *value in scrollableIds) { if (!scrollNode) { @@ -44,9 +46,9 @@ - (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)pro [promise reject:@"Cannot find scrollable view"]; return; } - NSDictionary *scrollRange = params[@"scrollRange"]; - CGFloat startAnchor = [scrollRange[@"start"] floatValue]; - CGFloat endAnchor = [scrollRange[@"end"] floatValue]; + NSDictionary *scrollRange = [params optObject:@"scrollRange"]; + CGFloat startAnchor = [[scrollRange optNumber:@"start"] floatValue]; + CGFloat endAnchor = [[scrollRange optNumber:@"end"] floatValue]; id target = params[@"target"]; BOOL isNavBar = false; DoricViewNode *targetNode = nil; @@ -66,10 +68,10 @@ - (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)pro [promise reject:@"Cannot find target view"]; } } - NSDictionary *changing = params[@"changing"]; - NSString *name = changing[@"name"]; - NSNumber *changingStart = changing[@"start"]; - NSNumber *changingEnd = changing[@"end"]; + NSDictionary *changing = [params optObject:@"changing"]; + NSString *name = [changing optString:@"name"]; + NSNumber *changingStart = [changing optNumber:@"start"]; + NSNumber *changingEnd = [changing optNumber:@"end"]; if ([scrollNode conformsToProtocol:@protocol(DoricScrollableProtocol)]) { __weak typeof(self) __self = self; [(id ) scrollNode addDidScrollBlock:^(UIScrollView *scrollView) { diff --git a/doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m index 222f7403..50fda3aa 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m @@ -31,13 +31,13 @@ - (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise { [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; __block DoricGravity gravity = DoricGravityBottom; - [dic[@"gravity"] also:^(NSNumber *it) { + [[dic optNumber:@"gravity"] also:^(NSNumber *it) { gravity = (DoricGravity) [it integerValue]; }]; if (self.doricContext.vc) { - ShowToastInVC(self.doricContext.vc, dic[@"msg"], gravity); + ShowToastInVC(self.doricContext.vc, [dic optString:@"msg"], gravity); } else { - ShowToast(dic[@"msg"], gravity); + ShowToast([dic optString:@"msg"], gravity); } }]; } @@ -46,10 +46,10 @@ - (void)alert:(NSDictionary *)dic withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"] - message:dic[@"msg"] + UIAlertController *alert = [UIAlertController alertControllerWithTitle:[dic optString:@"title"] + message:[dic optString:@"msg"] preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *action = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"OK", nil) + UIAlertAction *action = [UIAlertAction actionWithTitle:[dic optString:@"okLabel"] ?: NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [promise resolve:nil]; @@ -63,18 +63,18 @@ - (void)confirm:(NSDictionary *)dic withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"] - message:dic[@"msg"] + UIAlertController *alert = [UIAlertController alertControllerWithTitle:[dic optString:@"title"] + message:[dic optString:@"msg"] preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:dic[@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil) + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[dic optString:@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [promise reject:nil]; }]; [alert addAction:cancelAction]; - UIAlertAction *okAction = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"Ok", nil) + UIAlertAction *okAction = [UIAlertAction actionWithTitle:[dic optString:@"okLabel"] ?: NSLocalizedString(@"Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [promise resolve:nil]; @@ -89,11 +89,11 @@ - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"] - message:dic[@"msg"] + UIAlertController *alert = [UIAlertController alertControllerWithTitle:[dic optString:@"title"] + message:[dic optString:@"msg"] preferredStyle:UIAlertControllerStyleAlert]; - NSString *placeholder = dic[@"defaultText"]; - NSString *preText = dic[@"text"]; + NSString *placeholder = [dic optString:@"defaultText"]; + NSString *preText = [dic optString:@"text"]; [alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) { if (placeholder.length > 0) { textField.placeholder = placeholder; @@ -104,7 +104,7 @@ - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise { }]; __weak typeof(alert) _alert = alert; - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:dic[@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil) + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[dic optString:@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { __strong typeof(_alert) alert = _alert; @@ -112,7 +112,7 @@ - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise { }]; [alert addAction:cancelAction]; - UIAlertAction *okAction = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"Ok", nil) + UIAlertAction *okAction = [UIAlertAction actionWithTitle:[dic optString:@"okLabel"] ?: NSLocalizedString(@"Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { __strong typeof(_alert) alert = _alert; diff --git a/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m index 471f99d2..0d06be20 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m @@ -45,7 +45,7 @@ - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - [self.doricContext.navBar doric_navBar_setHidden:[param[@"hidden"] boolValue]]; + [self.doricContext.navBar doric_navBar_setHidden:[param optBool:@"hidden"]]; [promise resolve:nil]; }]; } else { @@ -58,7 +58,7 @@ - (void)setTitle:(NSDictionary *)param withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - [self.doricContext.navBar doric_navBar_setTitle:param[@"title"]]; + [self.doricContext.navBar doric_navBar_setTitle:[param optString:@"title"]]; [promise resolve:nil]; }]; } else { @@ -71,7 +71,7 @@ - (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - UIColor *color = DoricColor(param[@"color"]); + UIColor *color = DoricColor([param optNumber:@"color"]); [self.doricContext.navBar doric_navBar_setBackgroundColor:color]; [promise resolve:nil]; }]; @@ -85,8 +85,8 @@ - (void)setLeft:(NSDictionary *)params withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - NSString *viewId = params[@"id"]; - NSString *type = params[@"type"]; + NSString *viewId = [params optString:@"id"]; + NSString *type = [params optString:@"type"]; DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; if (!viewNode) { viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) { @@ -103,7 +103,7 @@ - (void)setLeft:(NSDictionary *)params withPromise:(DoricPromise *)promise { } }]; } - [viewNode blend:params[@"props"]]; + [viewNode blend:[params optObject:@"props"]]; [self.doricContext.navBar doric_navBar_setLeft:viewNode.view]; [promise resolve:nil]; }]; @@ -117,8 +117,8 @@ - (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - NSString *viewId = params[@"id"]; - NSString *type = params[@"type"]; + NSString *viewId = [params optString:@"id"]; + NSString *type = [params optString:@"type"]; DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; if (!viewNode) { viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) { @@ -135,7 +135,7 @@ - (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise { } }]; } - [viewNode blend:params[@"props"]]; + [viewNode blend:[params optObject:@"props"]]; [self.doricContext.navBar doric_navBar_setRight:viewNode.view]; [promise resolve:nil]; }]; @@ -149,8 +149,8 @@ - (void)setCenter:(NSDictionary *)params withPromise:(DoricPromise *)promise { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - NSString *viewId = params[@"id"]; - NSString *type = params[@"type"]; + NSString *viewId = [params optString:@"id"]; + NSString *type = [params optString:@"type"]; DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; if (!viewNode) { viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) { @@ -167,7 +167,7 @@ - (void)setCenter:(NSDictionary *)params withPromise:(DoricPromise *)promise { } }]; } - [viewNode blend:params[@"props"]]; + [viewNode blend:[params optObject:@"props"]]; [self.doricContext.navBar doric_navBar_setCenter:viewNode.view]; [promise resolve:nil]; }]; diff --git a/doric-iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.m index 4ce7ff9c..352183ec 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.m @@ -17,8 +17,9 @@ // Created by pengfei.zhou on 2019/11/23. // +#import #import "DoricNavigatorPlugin.h" - +#import "DoricExtensions.h" @implementation DoricNavigatorPlugin - (void)push:(NSDictionary *)params { @@ -26,17 +27,12 @@ - (void)push:(NSDictionary *)params { [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; BOOL animated = YES; - NSString *source = params[@"source"]; + NSString *source = [params optString:@"source"]; NSString *alias = source; - NSDictionary *config = params[@"config"]; + NSDictionary *config = [params optObject:@"config"]; if (config) { - if (config[@"animated"]) { - animated = [config[@"animated"] boolValue]; - } - - if (config[@"alias"]) { - alias = config[@"alias"]; - } + animated = [config optBool:@"animated" defaultValue:animated]; + alias = [config optString:@"alias" defaultValue:source]; } [self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]]; }]; @@ -46,10 +42,7 @@ - (void)pop:(NSDictionary *)params { __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; - BOOL animated = YES; - if (params[@"animated"]) { - animated = [params[@"animated"] boolValue]; - } + BOOL animated = [params optBool:@"animated" defaultValue:YES]; [self.doricContext.navigator doric_navigator_pop:animated]; }]; } diff --git a/doric-iOS/Pod/Classes/Plugin/DoricNetworkPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricNetworkPlugin.m index 2d03c35f..9499f0b1 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricNetworkPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricNetworkPlugin.m @@ -17,16 +17,17 @@ // Created by pengfei.zhou on 2019/11/21. // +#import #import "DoricNetworkPlugin.h" - +#import "DoricExtensions.h" @implementation DoricNetworkPlugin - (void)request:(NSDictionary *)dic withPromise:(DoricPromise *)promise { - NSString *url = dic[@"url"]; - NSString *method = dic[@"method"]; - NSDictionary *headers = dic[@"headers"]; - NSNumber *timeout = dic[@"timeout"]; - NSString *data = dic[@"data"]; + NSString *url = [dic optString:@"url"]; + NSString *method = [dic optString:@"method"]; + NSDictionary *headers = [dic optObject:@"headers"]; + NSNumber *timeout = [dic optNumber:@"timeout"]; + NSString *data = [dic optString:@"data"]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]]; request.HTTPMethod = method.uppercaseString; if (timeout) { diff --git a/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m index f10253f4..0348eb12 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m @@ -17,6 +17,8 @@ // Created by pengfei.zhou on 2020/1/8. // +#import +#import #import "DoricNotificationPlugin.h" @interface DoricNotificationPlugin () @@ -34,12 +36,12 @@ - (NSDictionary *)observers { } - (void)publish:(NSDictionary *)dic withPromise:(DoricPromise *)promise { - NSString *biz = dic[@"biz"]; - NSString *name = dic[@"name"]; + NSString *biz = [dic optString:@"biz"]; + NSString *name = [dic optString:@"name"]; if (biz) { name = [NSString stringWithFormat:@"__doric__%@#%@", biz, name]; } - NSString *data = dic[@"data"]; + NSString *data = [dic optString:@"data"]; NSDictionary *dataDic = nil; if (data) { NSData *jsonData = [data dataUsingEncoding:NSUTF8StringEncoding]; @@ -53,12 +55,12 @@ - (void)publish:(NSDictionary *)dic withPromise:(DoricPromise *)promise { } - (void)subscribe:(NSDictionary *)dic withPromise:(DoricPromise *)promise { - NSString *biz = dic[@"biz"]; - NSString *name = dic[@"name"]; + NSString *biz = [dic optString:@"biz"]; + NSString *name = [dic optString:@"name"]; if (biz) { name = [NSString stringWithFormat:@"__doric__%@#%@", biz, name]; } - NSString *callbackId = dic[@"callback"]; + NSString *callbackId = [dic optString:@"callback"]; __weak typeof(self) _self = self; id observer = [[NSNotificationCenter defaultCenter] addObserverForName:name diff --git a/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m index 8a8b1a6a..6a8436d0 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m @@ -32,8 +32,8 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise { } [superView bringSubviewToFront:self.fullScreenView]; self.fullScreenView.hidden = NO; - NSString *viewId = params[@"id"]; - NSString *type = params[@"type"]; + NSString *viewId = [params optString:@"id"]; + NSString *type = [params optString:@"type"]; DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; if (!viewNode) { viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) { @@ -51,14 +51,14 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise { } }]; } - [viewNode blend:params[@"props"]]; + [viewNode blend:[params optObject:@"props"]]; [self.fullScreenView.doricLayout apply]; [promise resolve:nil]; }]; } - (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise { - NSString *viewId = params[@"id"]; + NSString *viewId = [params optString:@"id"]; __weak typeof(self) _self = self; [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; diff --git a/doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m index ffa0ca8f..b06a59c2 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m @@ -23,6 +23,7 @@ #import "DoricShaderPlugin.h" #import "DoricRootNode.h" #import "DoricUtil.h" +#import "DoricExtensions.h" #import @@ -38,15 +39,15 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise { if (self.doricContext == nil) { return; } - NSString *viewId = argument[@"id"]; + NSString *viewId = [argument optString:@"id"]; - if (self.doricContext.rootNode.viewId == nil && [@"Root" isEqualToString:argument[@"type"]]) { + if (self.doricContext.rootNode.viewId == nil && [@"Root" isEqualToString:[argument optString:@"type"]]) { self.doricContext.rootNode.viewId = viewId; - [self.doricContext.rootNode blend:argument[@"props"]]; + [self.doricContext.rootNode blend:[argument optObject:@"props"]]; [self.doricContext.rootNode requestLayout]; } else { DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId]; - [viewNode blend:argument[@"props"]]; + [viewNode blend:[argument optObject:@"props"]]; [viewNode requestLayout]; } [promise resolve:nil]; @@ -60,9 +61,9 @@ - (void)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise { if (self.doricContext == nil) { return; } - NSArray *viewIds = argument[@"viewIds"]; + NSArray *viewIds = [argument optArray:@"viewIds"]; id args = argument[@"args"]; - NSString *name = argument[@"name"]; + NSString *name = [argument optString:@"name"]; DoricViewNode *viewNode = nil; for (NSString *viewId in viewIds) { if (!viewNode) { diff --git a/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m index 0a2f5f8c..2217b424 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricStatusBarPlugin.m @@ -19,7 +19,6 @@ #import "DoricStatusBarPlugin.h" #import "DoricUtil.h" -#import "DoricViewNode.h" #import "DoricExtensions.h" #import "DoricViewController.h" @@ -32,7 +31,7 @@ - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise { if (self.doricContext.navBar) { if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) { DoricViewController *target = ((DoricViewController *) self.doricContext.navBar); - target.statusBarHidden = [param[@"hidden"] boolValue]; + target.statusBarHidden = [param optBool:@"hidden"]; [target setNeedsStatusBarAppearanceUpdate]; } } @@ -46,7 +45,7 @@ - (void)setMode:(NSDictionary *)param withPromise:(DoricPromise *)promise { if (self.doricContext.navBar) { if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) { DoricViewController *target = ((DoricViewController *) self.doricContext.navBar); - target.statusBarMode = [param[@"mode"] intValue]; + target.statusBarMode = [[param optNumber:@"mode"] intValue]; [target setNeedsStatusBarAppearanceUpdate]; } } @@ -58,7 +57,7 @@ - (void)setColor:(NSDictionary *)param withPromise:(DoricPromise *)promise { [self.doricContext dispatchToMainQueue:^{ __strong typeof(_self) self = _self; if (self.doricContext.navBar) { - UIColor *color = DoricColor(param[@"color"]); + UIColor *color = DoricColor([param optNumber:@"color"]); [self.doricContext.navBar doric_navBar_setBackgroundColor:color]; } }]; diff --git a/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m index 933ba74e..e288cabd 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m @@ -22,6 +22,8 @@ #if __has_include() #import +#import +#import #define DoricCache PINCache @@ -161,9 +163,9 @@ - (DoricCache *)getDiskCache:(NSString *)zone { } - (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise { - NSString *zone = argument[@"zone"]; - NSString *key = argument[@"key"]; - NSString *value = argument[@"value"]; + NSString *zone = [argument optString:@"zone"]; + NSString *key = [argument optString:@"key"]; + NSString *value = [argument optString:@"value"]; DoricCache *diskCache = [self getDiskCache:zone]; [diskCache setObject:value forKey:key withBlock:^{ [promise resolve:nil]; @@ -171,8 +173,8 @@ - (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise { } - (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise { - NSString *zone = argument[@"zone"]; - NSString *key = argument[@"key"]; + NSString *zone = [argument optString:@"zone"]; + NSString *key = [argument optString:@"key"]; DoricCache *diskCache = [self getDiskCache:zone]; [diskCache objectForKey:key withBlock:^(NSString *_Nonnull key, id _Nullable object) { [promise resolve:object]; @@ -180,8 +182,8 @@ - (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise { } - (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise { - NSString *zone = argument[@"zone"]; - NSString *key = argument[@"key"]; + NSString *zone = [argument optString:@"zone"]; + NSString *key = [argument optString:@"key"]; DoricCache *diskCache = [self getDiskCache:zone]; [diskCache removeObjectForKey:key withBlock:^(NSString *key) { [promise resolve:nil]; @@ -189,7 +191,7 @@ - (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise { } - (void)clear:(NSDictionary *)argument withPromise:(DoricPromise *)promise { - NSString *zone = argument[@"zone"]; + NSString *zone = [argument optString:@"zone"]; DoricCache *diskCache = [self getDiskCache:zone]; [diskCache removeAllObjectsWithBlock:^{ [promise resolve:nil];