forked from Countly/countly-sdk-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CountlyLocationManager.m
79 lines (58 loc) · 1.83 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
// 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)sendLocationInfo
{
if (!CountlyConsentManager.sharedInstance.consentForLocation)
return;
[CountlyConnectionManager.sharedInstance sendLocationInfo];
}
- (void)recordLocationInfo:(CLLocationCoordinate2D)location city:(NSString *)city ISOCountryCode:(NSString *)ISOCountryCode andIP:(NSString *)IP
{
if (!CountlyConsentManager.sharedInstance.consentForLocation)
return;
if (CLLocationCoordinate2DIsValid(location))
self.location = [NSString stringWithFormat:@"%f,%f", location.latitude, location.longitude];
else
self.location = nil;
self.city = city;
self.ISOCountryCode = ISOCountryCode;
self.IP = IP;
if ((self.location || self.city || self.ISOCountryCode || self.IP))
self.isLocationInfoDisabled = NO;
[CountlyConnectionManager.sharedInstance sendLocationInfo];
}
- (void)disableLocationInfo
{
if (!CountlyConsentManager.sharedInstance.consentForLocation)
return;
self.isLocationInfoDisabled = YES;
//NOTE: Set location to empty string, as Countly Server needs it for disabling geo-location
self.location = @"";
self.city = nil;
self.ISOCountryCode = nil;
self.IP = nil;
[CountlyConnectionManager.sharedInstance sendLocationInfo];
}
@end