forked from illusionspaces/WKJavaScriptBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWKMsgCommand.m
More file actions
executable file
·57 lines (47 loc) · 1.76 KB
/
Copy pathWKMsgCommand.m
File metadata and controls
executable file
·57 lines (47 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// WKMsgCommand.m
// WKJavaScriptBridge-demo
//
// Created by Kevin on 2019/10/22.
// Copyright © 2019 王凯. All rights reserved.
//
#import "WKMsgCommand.h"
static const NSString const * kMessageCallbackId = @"callbackId";
static const NSString const * kMessageService = @"service";
static const NSString const * kMessageAction = @"action";
static const NSString const * kMessageActionArgs = @"actionArgs";
@interface WKMsgCommand ()
@property (nonatomic, readwrite) NSDictionary* arguments;
@property (nonatomic, readwrite) NSString* callbackId;
@property (nonatomic, readwrite) NSString* className;
@property (nonatomic, readwrite) NSString* methodName;
@end
@implementation WKMsgCommand
+ (WKMsgCommand *)commandFromJson:(NSDictionary *)jsonEntry {
return [[WKMsgCommand alloc] initFromJson:jsonEntry];
}
- (id)initFromJson:(NSDictionary *)jsonEntry {
id tmp = [jsonEntry objectForKey:kMessageCallbackId];
NSString *callbackId = tmp == [NSNull null] ? nil : tmp;
NSString *className = [jsonEntry objectForKey:kMessageService];
NSString *methodName = [jsonEntry objectForKey:kMessageAction];
NSDictionary *arguments = [jsonEntry objectForKey:kMessageActionArgs];
return [self initWithArguments:arguments
callbackId:callbackId
className:className
methodName:methodName];
}
- (id)initWithArguments:(NSDictionary *)arguments
callbackId:(NSString *)callbackId
className:(NSString *)className
methodName:(NSString *)methodName {
self = [super init];
if (self != nil) {
_arguments = arguments;
_callbackId = callbackId;
_className = className;
_methodName = methodName;
}
return self;
}
@end