-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLLocationManager+Doraemon.m
40 lines (33 loc) · 1.24 KB
/
CLLocationManager+Doraemon.m
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
//
// CLLocationManager+Doraemon.m
// DoraemonKit-DoraemonKit
//
// Created by yixiang on 2018/7/4.
//
#import "CLLocationManager+Doraemon.h"
#import "DoraemonGPSMocker.h"
#import <objc/runtime.h>
@implementation CLLocationManager (Doraemon)
- (void)doraemon_swizzleLocationDelegate:(id)delegate {
if (delegate) {
[self doraemon_swizzleLocationDelegate:[DoraemonGPSMocker shareInstance]];
[[DoraemonGPSMocker shareInstance] addLocationBinder:self delegate:delegate];
Protocol *proto = objc_getProtocol("CLLocationManagerDelegate");
unsigned int count;
struct objc_method_description *methods = protocol_copyMethodDescriptionList(proto, NO, YES, &count);
NSMutableArray *array = [NSMutableArray array];
for(unsigned i = 0; i < count; i++)
{
SEL sel = methods[i].name;
if ([delegate respondsToSelector:sel]) {
if (![[DoraemonGPSMocker shareInstance] respondsToSelector:sel]) {
NSAssert(NO, @"Delegate : %@ not implementation SEL : %@",delegate,NSStringFromSelector(sel));
}
}
}
free(methods);
}else{
[self doraemon_swizzleLocationDelegate:delegate];
}
}
@end