forked from Countly/countly-sdk-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CountlyLocationManager.m
92 lines (69 loc) · 2.35 KB
/
CountlyLocationManager.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// CountlyLocationManager.m
//
// This code is provided under the MIT License.
//
// Please visit www.count.ly for more information.
#import "CountlyCommon.h"
@implementation CountlyLocationManager
+ (instancetype)sharedInstance
{
if (!CountlyCommon.sharedInstance.hasStarted)
return nil;
static CountlyLocationManager* s_sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{s_sharedInstance = self.new;});
return s_sharedInstance;
}
- (instancetype)init
{
if (self = [super init])
{
}
return self;
}
#pragma mark ---
- (void)recordLocation:(CLLocationCoordinate2D)location city:(NSString *)city ISOCountryCode:(NSString *)ISOCountryCode IP:(NSString *)IP
{
if (!CountlyConsentManager.sharedInstance.consentForLocation)
return;
[self updateLocation:location city:city ISOCountryCode:ISOCountryCode IP:IP];
[CountlyConnectionManager.sharedInstance sendLocationInfo];
}
- (void)updateLocation:(CLLocationCoordinate2D)location city:(NSString *)city ISOCountryCode:(NSString *)ISOCountryCode IP:(NSString *)IP
{
if (CLLocationCoordinate2DIsValid(location))
self.location = [NSString stringWithFormat:@"%f,%f", location.latitude, location.longitude];
else
self.location = nil;
self.city = city.length ? city : nil;
self.ISOCountryCode = ISOCountryCode.length ? ISOCountryCode : nil;
self.IP = IP.length ? IP : nil;
if (self.city && !self.ISOCountryCode)
{
CLY_LOG_W(@"City and Country Code should be set as a pair. Country Code is missing while City is set!");
}
else if (self.ISOCountryCode && !self.city)
{
CLY_LOG_W(@"City and Country Code should be set as a pair. City is missing while Country Code is set!");
}
if ((self.location || self.city || self.ISOCountryCode || self.IP))
self.isLocationInfoDisabled = NO;
}
- (void)sendLocationInfo
{
if (!CountlyConsentManager.sharedInstance.consentForLocation)
return;
[CountlyConnectionManager.sharedInstance sendLocationInfo];
}
- (void)disableLocationInfo
{
if (!CountlyConsentManager.sharedInstance.consentForLocation)
return;
self.isLocationInfoDisabled = YES;
self.location = nil;
self.city = nil;
self.ISOCountryCode = nil;
self.IP = nil;
[CountlyConnectionManager.sharedInstance sendLocationInfo];
}
@end