57
57
#pragma clang diagnostic push
58
58
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
59
59
60
- typedef struct os_location_coordinate {
61
- double latitude;
62
- double longitude;
63
- } os_location_coordinate;
64
-
65
- typedef struct os_last_location {
66
- os_location_coordinate cords;
67
- double verticalAccuracy;
68
- double horizontalAccuracy;
69
- } os_last_location;
70
-
71
60
static ONE_S_LOG_LEVEL _nsLogLevel = ONE_S_LL_WARN;
72
61
static ONE_S_LOG_LEVEL _visualLogLevel = ONE_S_LL_NONE;
73
62
82
71
83
72
@implementation OneSignal
84
73
85
- NSString * const ONESIGNAL_VERSION = @" 020009 " ;
74
+ NSString * const ONESIGNAL_VERSION = @" 020010 " ;
86
75
87
76
static bool registeredWithApple = false ; // Has attempted to register for push notifications with Apple.
88
77
static OneSignalTrackIAP* trackIAPPurchase;
89
78
static NSString * app_id;
90
79
NSString * emailToSet;
91
80
NSMutableDictionary * tagsToSend;
92
- os_last_location *lastLocation;
93
- BOOL location_event_fired;
94
81
NSString * mUserId;
95
82
NSString * mDeviceToken;
96
83
OneSignalHTTPClient *httpClient;
@@ -132,7 +119,7 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId
132
119
if ([@" b2f7f966-d8cc-11eg-bed1-df8f05be55ba" isEqualToString: appId] || [@" 5eb5a37e-b458-11e3-ac11-000c2940e62c" isEqualToString: appId])
133
120
onesignal_Log (ONE_S_LL_WARN, @" OneSignal Example AppID detected, please update to your app's id found on OneSignal.com" );
134
121
135
- [OneSignalLocation getLocation: [OneSignalHelper sharedInstance ] prompt: false ];
122
+ [OneSignalLocation getLocation: false ];
136
123
137
124
if (self) {
138
125
@@ -483,7 +470,7 @@ + (void)setSubscription:(BOOL)enable {
483
470
}
484
471
485
472
+ (void ) promptLocation {
486
- [OneSignalLocation getLocation: [OneSignalHelper sharedInstance ] prompt: true ];
473
+ [OneSignalLocation getLocation: true ];
487
474
}
488
475
489
476
+ (void )registerDeviceToken : (id )inDeviceToken onSuccess : (OSResultSuccessBlock)successBlock onFailure : (OSFailureBlock)failureBlock {
@@ -642,12 +629,12 @@ + (void)registerUser {
642
629
NSData * postData = [NSJSONSerialization dataWithJSONObject: dataDic options: 0 error: nil ];
643
630
[request setHTTPBody: postData];
644
631
645
- if (lastLocation) {
646
- dataDic[@" lat" ] = [NSNumber numberWithDouble: lastLocation->cords.latitude];
647
- dataDic[@" long" ] = [NSNumber numberWithDouble: lastLocation->cords.longitude];
648
- dataDic[@" loc_acc_vert" ] = [NSNumber numberWithDouble: lastLocation->verticalAccuracy];
649
- dataDic[@" loc_acc" ] = [NSNumber numberWithDouble: lastLocation->horizontalAccuracy];
650
- lastLocation = nil ;
632
+ if ([OneSignalLocation lastLocation ] ) {
633
+ dataDic[@" lat" ] = [NSNumber numberWithDouble: [OneSignalLocation lastLocation ] ->cords.latitude];
634
+ dataDic[@" long" ] = [NSNumber numberWithDouble: [OneSignalLocation lastLocation ] ->cords.longitude];
635
+ dataDic[@" loc_acc_vert" ] = [NSNumber numberWithDouble: [OneSignalLocation lastLocation ] ->verticalAccuracy];
636
+ dataDic[@" loc_acc" ] = [NSNumber numberWithDouble: [OneSignalLocation lastLocation ] ->horizontalAccuracy];
637
+ [OneSignalLocation clearLastLocation ] ;
651
638
}
652
639
653
640
[OneSignalHelper enqueueRequest: request onSuccess: ^(NSDictionary * results) {
@@ -672,10 +659,8 @@ + (void)registerUser {
672
659
tagsToSend = nil ;
673
660
}
674
661
675
- if (lastLocation) {
676
- [self sendLocation: lastLocation];
677
- lastLocation = nil ;
678
- }
662
+ // try to send location
663
+ [OneSignalLocation sendLocation ];
679
664
680
665
if (emailToSet) {
681
666
[OneSignal syncHashedEmail: emailToSet];
@@ -1038,64 +1023,6 @@ + (void)processLocalActionBasedNotification:(UILocalNotification*) notification
1038
1023
1039
1024
}
1040
1025
1041
-
1042
- - (void )locationManager : (id )manager didUpdateLocations : (NSArray *)locations {
1043
-
1044
- #pragma clang diagnostic push
1045
- #pragma clang diagnostic ignored "-Wundeclared-selector"
1046
- [manager performSelector: @selector (stopUpdatingLocation )];
1047
- #pragma clang diagnostic pop
1048
-
1049
- if (location_event_fired)
1050
- return ;
1051
-
1052
- location_event_fired = true ;
1053
-
1054
- id location = locations.lastObject ;
1055
-
1056
- SEL cord_selector = NSSelectorFromString (@" coordinate" );
1057
- os_location_coordinate cords;
1058
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [[location class ] instanceMethodSignatureForSelector: cord_selector]];
1059
-
1060
- [invocation setTarget: locations.lastObject];
1061
- [invocation setSelector: cord_selector];
1062
- [invocation invoke ];
1063
- [invocation getReturnValue: &cords];
1064
-
1065
- os_last_location *currentLocation = (os_last_location*)malloc (sizeof (os_last_location));
1066
- currentLocation->verticalAccuracy = [[location valueForKey: @" verticalAccuracy" ] doubleValue ];
1067
- currentLocation->horizontalAccuracy = [[location valueForKey: @" horizontalAccuracy" ] doubleValue ];
1068
- currentLocation->cords = cords;
1069
-
1070
- if (mUserId == nil ) {
1071
- lastLocation = currentLocation;
1072
- return ;
1073
- }
1074
-
1075
- [OneSignal sendLocation: currentLocation];
1076
- }
1077
-
1078
- + (void ) sendLocation : (os_last_location*)location {
1079
-
1080
- NSMutableURLRequest * request = [httpClient requestWithMethod: @" PUT" path: [NSString stringWithFormat: @" players/%@ " , mUserId]];
1081
-
1082
- NSDictionary * dataDic = [NSDictionary dictionaryWithObjectsAndKeys:
1083
- app_id, @" app_id" ,
1084
- [NSNumber numberWithDouble: location->cords.latitude], @" lat" ,
1085
- [NSNumber numberWithDouble: location->cords.longitude], @" long" ,
1086
- [NSNumber numberWithDouble: location->verticalAccuracy], @" loc_acc_vert" ,
1087
- [NSNumber numberWithDouble: location->horizontalAccuracy], @" loc_acc" ,
1088
- [OneSignalHelper getNetType ], @" net_type" ,
1089
- nil ];
1090
-
1091
- NSData * postData = [NSJSONSerialization dataWithJSONObject: dataDic options: 0 error: nil ];
1092
- [request setHTTPBody: postData];
1093
-
1094
- [OneSignalHelper enqueueRequest: request
1095
- onSuccess: nil
1096
- onFailure: nil ];
1097
- }
1098
-
1099
1026
#if XC8_AVAILABLE
1100
1027
1101
1028
static id <OSUserNotificationCenterDelegate> notificationCenterDelegate;
0 commit comments