Commit e98c4fb6d416264311b19476b76bcf5b2fe5c9c6

Authored by daojian
1 parent ae7cc951

0.3.5 解决转发好友失败发生崩溃

CNLiveNewIMAManagerKit.podspec
... ... @@ -8,7 +8,7 @@
8 8  
9 9 Pod::Spec.new do |s|
10 10 s.name = 'CNLiveNewIMAManagerKit'
11   - s.version = '0.3.4'
  11 + s.version = '0.3.5'
12 12 s.summary = 'A short description of CNLiveNewIMAManagerKit.'
13 13  
14 14 #s.description = <<-DESC
... ...
CNLiveNewIMAManagerKit/Classes/TIMModel/Conversation/IMAConversation.m
... ... @@ -512,11 +512,14 @@
512 512 }
513 513 }
514 514  
515   - if (block)
516   - {
517   - block(array, YES, 0);
518   - }
519   - [[NSNotificationCenter defaultCenter] postNotificationName:KIMAMSG_SendImageSuccessNotication object:array];
  515 + dispatch_async(dispatch_get_main_queue(), ^{
  516 + if (block)
  517 + {
  518 + block(array, YES, 0);
  519 + }
  520 + [[NSNotificationCenter defaultCenter] postNotificationName:KIMAMSG_SendImageSuccessNotication object:array];
  521 + });
  522 +
520 523  
521 524 } fail:^(int code, NSString *err) {
522 525 [msg changeTo:EIMAMsg_SendFail needRefresh:YES];
... ... @@ -536,10 +539,14 @@
536 539 if (code == 115128) {
537 540 NSLog(@"发送文件超出最大范围");
538 541 }
539   - if (block)
540   - {
541   - block(array, NO, code);
542   - }
  542 +
  543 + dispatch_async(dispatch_get_main_queue(), ^{
  544 + if (block)
  545 + {
  546 + block(array, NO, code);
  547 + }
  548 + });
  549 +
543 550 }];
544 551 });
545 552  
... ...
Example/CNLiveNewIMAManagerKit/CNLIVEViewController.h
... ... @@ -7,6 +7,7 @@
7 7 //
8 8  
9 9 @import UIKit;
  10 +@import JavaScriptCore;
10 11  
11 12 @interface CNLIVEViewController : UIViewController
12 13  
... ...
Example/CNLiveNewIMAManagerKit/CNLIVEViewController.m
... ... @@ -42,14 +42,74 @@
42 42 }
43 43 - (void)setAction
44 44 {
45   - [[CNTransferBalanceUnreceivedCache cache] addOneElement:@{@"sourceId": @"1222",
46   - @"fromId" : @"1111",
47   - @"type" : @"1",
48   - } forKey:@"key1"];
  45 +// [[CNTransferBalanceUnreceivedCache cache] addOneElement:@{@"sourceId": @"1222",
  46 +// @"fromId" : @"1111",
  47 +// @"type" : @"1",
  48 +// } forKey:@"key1"];
49 49 }
50 50 - (void)getAction
51 51 {
52   - NSArray *array = [[CNTransferBalanceUnreceivedCache cache] objectForKey:@"key1"];
53   - NSLog(@"array = %@",array);
  52 +// NSArray *array = [[CNTransferBalanceUnreceivedCache cache] objectForKey:@"key1"];
  53 +// NSLog(@"array = %@",array);
  54 + // 创建 JSVirtualMachine 对象 jsvmJSVirtualMachine *jsvm = [[JSVirtualMachine alloc] init];// 使用 jsvm 的 JSContext 对象 ctJSContext *ct = [[JSContext alloc] initWithVirtualMachine:jsvm];
  55 + JSVirtualMachine *jsvm = [[JSVirtualMachine alloc] init];
  56 + JSContext *context = [[JSContext alloc] initWithVirtualMachine:jsvm];
  57 +// JSContext *context = [[JSContext alloc] init];
  58 + // 解析执行 JavaScript 脚本[context evaluateScript:@"var i = 4 + 8"];// 转换 i 变量为原生对象NSNumber *number = [context[@"i"] toNumber];NSLog(@"var i is %@, number is %@",context[@"i"], number);
  59 + [context evaluateScript:@"var a = 4 + 8"];
  60 + NSNumber *number = [context[@"a"] toNumber];
  61 + NSInteger a = [number integerValue];
  62 + NSLog(@"var i is %@, number is %@",context[@"a"], number);
  63 +
  64 +// 解析执行 JavaScript 脚本[context evaluateScript:@"function addition(x, y) { return x + y}"];// 获得 addition 函数JSValue *addition = context[@"addition"];// 传入参数执行 addition 函数JSValue *resultValue = [addition callWithArguments:@[@(4), @(8)]];// 将 addition 函数执行的结果转成原生 NSNumber 来使用。NSLog(@"function is %@; reslutValue is %@",addition, [resultValue toNumber]);
  65 +
  66 + [context evaluateScript:@"function addition(x, y) {}"];
  67 + JSValue *addition = context[@"addition"];
  68 + id fun = [addition toObject];
  69 + if ([addition isDate]) {
  70 + printf("[addition isDate]");
  71 + }
  72 + if ([addition isUndefined]) {
  73 + printf("isUndefined");
  74 + }
  75 + if ([addition isNull]) {
  76 + printf("null");
  77 + }
  78 + if ([addition isNumber]) {
  79 + printf("isNumber");
  80 + }
  81 + if ([addition isString]) {
  82 + printf("isString");
  83 + }
  84 +
  85 +
  86 + if ([addition isBoolean]) {
  87 + printf("isBoolean");
  88 + }
  89 + if ([addition isObject]) {
  90 + printf("isObject");
  91 + }
  92 + if ([addition isArray]) {
  93 + printf("isArray");
  94 + }
  95 + if ([addition isSymbol]) {
  96 + printf("isSymbol");
  97 + }
  98 + JSValue *resultValue = [addition callWithArguments:@[@(4),@(8)]];
  99 + NSNumber *sumNumber = [resultValue toNumber];
  100 + NSInteger sum = [sumNumber integerValue];
  101 +
  102 + NSLog(@"function is %@; reslutValue is %@",addition, [resultValue toNumber]);
  103 +
  104 + [[context globalObject] invokeMethod:@"" withArguments:@[]];
  105 +
  106 +// - (JSValue *)callJSMethod:(NSString *)method args:(NSArray *)args {
  107 +// WXLogDebug(@"Calling JS... method:%@, args:%@", method, args);
  108 +// return [[_jsContext globalObject] invokeMethod:method withArguments:args];
  109 +//
  110 +// }
  111 +
  112 + // 在 JSContext 中使用原生 Block 设置一个减法 subtraction 函数context[@"subtraction"] = ^(int x, int y) { return x - y;};// 在同一个 JSContext 里用 JavaScript 代码来调用原生 subtraction 函数JSValue *subValue = [context evaluateScript:@"subtraction(4,8);"];NSLog(@"substraction(4,8) is %@",[subValue toNumber]);
  113 +
54 114 }
55 115 @end
... ...