YHNative.m
1.93 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// YHNative.m
// YohoExplorerDemo
//
// Created by gaoqiang xu on 4/7/15.
// Copyright (c) 2015 gaoqiang xu. All rights reserved.
//
#import "YHNative.h"
#import <objc/message.h>
#import "YHNativeCamera.h"
#import "YHNaviteLBS.h"
#import "YHNativeMedia.h"
#import "YHNativeDevice.h"
#import "YHNativeMotion.h"
#import "YHNativeFS.h"
@implementation YHNative
+ (Class)resolveActionName:(NSString *)name
{
if ([name isEqualToString:YHNative_Camera]) {
return [YHNativeCamera class];
} else if ([name isEqualToString:YHNative_LBS]) {
return [YHNaviteLBS class];
} else if ([name isEqualToString:YHNative_Media]) {
return [YHNativeMedia class];
} else if ([name isEqualToString:YHNative_Device]) {
return [YHNativeDevice class];
} else if ([name isEqualToString:YHNative_Motion]) {
return [YHNativeMotion class];
} else if ([name isEqualToString:YHNative_FS]) {
return [YHNativeFS class];
}
return nil;
}
- (void)workWithMethod:(SEL)method options:(NSDictionary *)options success:(onSuccess)success failure:(onFailure)failure
{
self.options = options;
self.successCallBack = success;
self.failureCallBack = failure;
NSString *methodName = NSStringFromSelector(method);
NSArray *functions = [self availableFunctions];
NSArray *function = [functions filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF = %@", methodName]];
if (function.count == 1) {
dispatch_async(dispatch_get_main_queue(), ^{
((void (*)(id, SEL))objc_msgSend)(self, method);
});
} else {
NSString *message = [[NSString alloc] initWithFormat:@"No such action:%@ found on %@", methodName, NSStringFromClass([self class])];
self.failureCallBack(message);
}
}
- (NSArray *)availableFunctions
{
return nil;
}
- (NSString *)actionName
{
return nil;
}
@end