3131 */
3232
3333#import " AAChartView.h"
34+ #import " AAJsonConverter.h"
3435
3536@implementation AAWeakProxy
3637
@@ -529,6 +530,12 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat
529530- (void )drawChart {
530531 if (_beforeDrawChartJavaScript) {
531532 [self safeEvaluateJavaScriptString: _beforeDrawChartJavaScript];
533+
534+ // console 输出一下_beforeDrawChartJavaScript,方便调试
535+ AADetailLog (@" Before Drawing Chart JavaScript String: %@ " ,_beforeDrawChartJavaScript);
536+
537+ // beforeDrawChartJavaScript 执行完毕后置空,防止重复调用
538+ _beforeDrawChartJavaScript = nil ;
532539 }
533540
534541 NSString *jsStr = [NSString stringWithFormat: @" loadTheHighChartView('%@ ','%f ','%f ')" ,
@@ -539,6 +546,12 @@ - (void)drawChart {
539546
540547 if (_afterDrawChartJavaScript) {
541548 [self safeEvaluateJavaScriptString: _afterDrawChartJavaScript];
549+
550+ // console 输出一下_afterDrawChartJavaScript,方便调试
551+ AADetailLog (@" After Drawing Chart JavaScript String: %@ " ,_afterDrawChartJavaScript);
552+
553+ // afterDrawChartJavaScript 执行完毕后置空,防止重复调用
554+ _afterDrawChartJavaScript = nil ;
542555 }
543556}
544557
@@ -752,107 +765,5 @@ - (void)dealloc {
752765
753766
754767
755- #import < objc/runtime.h>
756-
757- @implementation AAJsonConverter
758-
759- + (NSDictionary *)dictionaryWithObjectInstance : (id )objc {
760- unsigned int propsCount;
761- objc_property_t *props = class_copyPropertyList ([objc class ], &propsCount);
762- NSMutableDictionary *propsDic = [NSMutableDictionary dictionaryWithCapacity: propsCount];
763-
764- for (NSUInteger i = 0 ; i < propsCount; i++) {
765- objc_property_t prop = props[i];
766- NSString *propName = [NSString stringWithUTF8String: property_getName (prop)];
767- id value = [objc valueForKey: propName];
768- if (value == nil ) {
769- value = [NSNull null ];
770- continue ;
771- } else {
772- value = [self getObjectInternal: value];
773- }
774- propsDic[propName] = value;
775- }
776- free (props);
777-
778- return propsDic;
779- }
780-
781- + (id )getObjectInternal : (id )objc {
782- if ( [objc isKindOfClass: [NSString class ]]
783- || [objc isKindOfClass: [NSNumber class ]]
784- || [objc isKindOfClass: [NSNull class ]] ) {
785- return objc;
786- }
787-
788- if ([objc isKindOfClass: [NSArray class ]]) {
789- NSArray *objcArr = objc;
790- NSMutableArray *arr = [NSMutableArray arrayWithCapacity: objcArr.count];
791- for (id element in objcArr) {
792- [arr addObject: [self getObjectInternal: element]];
793- }
794- return arr;
795- }
796-
797- if ([objc isKindOfClass: [NSDictionary class ]]) {
798- NSDictionary *objcDic = objc;
799- NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity: [objcDic count ]];
800- NSArray *allKeys = objcDic.allKeys ;
801- for (NSString *key in allKeys) {
802- dic[key] = [self getObjectInternal: objcDic[key]];
803- }
804- return dic;
805- }
806-
807- return [self dictionaryWithObjectInstance: objc];
808- }
809-
810- + (NSString *)pureOptionsJsonStringWithOptionsInstance : (id )optionsObject {
811- NSDictionary *dic;
812- if ([optionsObject isKindOfClass: [NSDictionary class ]] ) {
813- dic = optionsObject;
814- } else {
815- dic = [self dictionaryWithObjectInstance: optionsObject];
816- }
817- #if DEBUG
818- [AAJsonConverter printPrettyPrintedJsonStringWithJsonObject: dic];
819- #endif
820- return [self pureJsonStringWithJsonObject: dic];
821- }
822-
823- + (NSString *)pureJsonStringWithJsonObject : (id )jsonObject {
824- NSError *error = nil ;
825- NSData *jsonData = [NSJSONSerialization dataWithJSONObject: jsonObject
826- options: kNilOptions
827- error: &error];
828- NSString *pureJsonStr =[[NSString alloc ] initWithData: jsonData encoding: NSUTF8StringEncoding];
829- if (error) {
830- AADetailLog (@" ❌❌❌ pure JSONString with JSONObject serialization failed:%@ " , error);
831- return nil ;
832- }
833- return pureJsonStr;
834- }
835-
836- #if DEBUG
837- + (NSString *)printPrettyPrintedJsonStringWithJsonObject : (id )jsonObject {
838- NSError *error = nil ;
839- NSData *jsonData = [NSJSONSerialization dataWithJSONObject: jsonObject
840- options: NSJSONWritingPrettyPrinted
841- error: &error];
842- NSString *jsonStr =[[NSString alloc ] initWithData: jsonData encoding: NSUTF8StringEncoding];
843- NSLog (@" ----------- console log AAOptions JSON information of AAChartView -----------:\n %@ " ,jsonStr);
844-
845- if (error) {
846- NSLog (@" ❌❌❌ pretty printed JSONString with JSONObject serialization failed:%@ " , error);
847- return nil ;
848- }
849- return jsonStr;
850- }
851- #endif
852-
853-
854- @end
855-
856-
857768
858769
0 commit comments