Skip to content

Commit 81bd792

Browse files
committed
Merge pull request #22 from one-signal/fix_missing_additional_data_meta_fields
Added geotagging
2 parents 8014bc5 + 343491b commit 81bd792

File tree

8 files changed

+224
-7
lines changed

8 files changed

+224
-7
lines changed

iOS_SDK/Framework/OneSignal.framework/Versions/A/Headers/OneSignal.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
* limitations under the License.
1919
*/
2020

21-
#import <Foundation/Foundation.h>
22-
#import <objc/runtime.h>
23-
2421
typedef void (^OneSignalResultSuccessBlock)(NSDictionary* result);
2522
typedef void (^OneSignalFailureBlock)(NSError* error);
2623
typedef void (^OneSignalIdsAvailableBlock)(NSString* userId, NSString* pushToken);
@@ -105,5 +102,7 @@ typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) {
105102
- (void)postNotification:(NSDictionary*)jsonData onSuccess:(OneSignalResultSuccessBlock)successBlock onFailure:(OneSignalFailureBlock)failureBlock;
106103
- (void)postNotificationWithJsonString:(NSString*)jsonData onSuccess:(OneSignalResultSuccessBlock)successBlock onFailure:(OneSignalFailureBlock)failureBlock;
107104

105+
- (void)promptLocation;
106+
108107
@end
109108

213 KB
Binary file not shown.

iOS_SDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
37E277281ACCA5B300D49C8D /* GameThrive.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 37E277241ACBB58D00D49C8D /* GameThrive.h */; };
3333
37E2772A1ACCA67400D49C8D /* OneSignal.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 37E277041ACB940000D49C8D /* OneSignal.h */; };
3434
37E6B2BB19D9CAF300D0C601 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 37E6B2BA19D9CAF300D0C601 /* UIKit.framework */; };
35+
91F2D1031C94D10F00DE95D0 /* OneSignalLocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 91F2D1021C94D10F00DE95D0 /* OneSignalLocation.m */; };
3536
/* End PBXBuildFile section */
3637

3738
/* Begin PBXCopyFilesBuildPhase section */
@@ -75,6 +76,8 @@
7576
37E277241ACBB58D00D49C8D /* GameThrive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameThrive.h; sourceTree = "<group>"; };
7677
37E277251ACBB58D00D49C8D /* GameThrive.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameThrive.m; sourceTree = "<group>"; };
7778
37E6B2BA19D9CAF300D0C601 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
79+
91F2D1011C94D0DD00DE95D0 /* OneSignalLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OneSignalLocation.h; sourceTree = "<group>"; };
80+
91F2D1021C94D10F00DE95D0 /* OneSignalLocation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OneSignalLocation.m; sourceTree = "<group>"; };
7881
/* End PBXFileReference section */
7982

8083
/* Begin PBXFrameworksBuildPhase section */
@@ -147,6 +150,8 @@
147150
37747FBD1914837300558FAD /* OneSignalHTTPClient.m */,
148151
371FDED819F1A486001479B7 /* OneSignalTrackIAP.m */,
149152
371FDEDA19F1F9D9001479B7 /* OneSignalTrackIAP.h */,
153+
91F2D1011C94D0DD00DE95D0 /* OneSignalLocation.h */,
154+
91F2D1021C94D10F00DE95D0 /* OneSignalLocation.m */,
150155
);
151156
path = OneSignal;
152157
sourceTree = "<group>";
@@ -245,6 +250,7 @@
245250
37D6E07F1B1EAE6500EC3624 /* OneSignalMobileProvision.m in Sources */,
246251
37668EE91AA80B7E0095D813 /* OneSignalReachability.m in Sources */,
247252
37E277051ACB940000D49C8D /* OneSignal.m in Sources */,
253+
91F2D1031C94D10F00DE95D0 /* OneSignalLocation.m in Sources */,
248254
);
249255
runOnlyForDeploymentPostprocessing = 0;
250256
};
-16 KB
Binary file not shown.

iOS_SDK/OneSignal/OneSignal.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
* limitations under the License.
1919
*/
2020

21-
#import <Foundation/Foundation.h>
22-
#import <objc/runtime.h>
23-
2421
typedef void (^OneSignalResultSuccessBlock)(NSDictionary* result);
2522
typedef void (^OneSignalFailureBlock)(NSError* error);
2623
typedef void (^OneSignalIdsAvailableBlock)(NSString* userId, NSString* pushToken);
@@ -105,5 +102,7 @@ typedef NS_ENUM(NSUInteger, ONE_S_LOG_LEVEL) {
105102
- (void)postNotification:(NSDictionary*)jsonData onSuccess:(OneSignalResultSuccessBlock)successBlock onFailure:(OneSignalFailureBlock)failureBlock;
106103
- (void)postNotificationWithJsonString:(NSString*)jsonData onSuccess:(OneSignalResultSuccessBlock)successBlock onFailure:(OneSignalFailureBlock)failureBlock;
107104

105+
- (void)promptLocation;
106+
108107
@end
109108

iOS_SDK/OneSignal/OneSignal.m

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#import "OneSignalJailbreakDetection.h"
2525
#import "OneSignalReachability.h"
2626
#import "OneSignalMobileProvision.h"
27+
#import "OneSignalLocation.h"
2728

2829
#import <stdlib.h>
2930
#import <stdio.h>
@@ -60,7 +61,7 @@ @interface OneSignal ()
6061

6162
@implementation OneSignal
6263

63-
NSString* const ONESIGNAL_VERSION = @"011103";
64+
NSString* const ONESIGNAL_VERSION = @"011200";
6465

6566
@synthesize app_id = _GT_publicKey;
6667
@synthesize httpClient = _GT_httpRequest;
@@ -90,6 +91,21 @@ @implementation OneSignal
9091
bool mSubscriptionSet = true;
9192
static NSString* mSDKType = @"native";
9293

94+
95+
typedef struct os_location_coordinate {
96+
double latitude;
97+
double longitude;
98+
} os_location_coordinate;
99+
100+
typedef struct os_last_location {
101+
os_location_coordinate cords;
102+
double verticalAccuracy;
103+
double horizontalAccuracy;
104+
} os_last_location;
105+
106+
static os_last_location *lastLocation;
107+
static bool location_event_fired;
108+
93109
+ (void)setMSDKType:(NSString*)str {
94110
mSDKType = str;
95111
}
@@ -133,6 +149,8 @@ - (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId
133149
onesignal_Log(ONE_S_LL_WARN, @"OneSignal Example AppID detected, please update to your app's id found on OneSignal.com");
134150

135151

152+
[OneSignalLocation getLocation:self prompt:false];
153+
136154
if (self) {
137155

138156
handleNotification = callback;
@@ -421,6 +439,14 @@ - (void)registerUser {
421439
NSData* postData = [NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil];
422440
[request setHTTPBody:postData];
423441

442+
if (lastLocation) {
443+
dataDic[@"lat"] = [NSNumber numberWithDouble:lastLocation->cords.latitude];
444+
dataDic[@"long"] = [NSNumber numberWithDouble:lastLocation->cords.longitude];
445+
dataDic[@"loc_acc_vert"] = [NSNumber numberWithDouble:lastLocation->verticalAccuracy];
446+
dataDic[@"loc_acc"] = [NSNumber numberWithDouble:lastLocation->horizontalAccuracy];
447+
lastLocation = nil;
448+
}
449+
424450
[self enqueueRequest:request onSuccess:^(NSDictionary* results) {
425451
oneSignalReg = true;
426452
waitingForOneSReg = false;
@@ -435,6 +461,7 @@ - (void)registerUser {
435461

436462
if (tagsToSend != nil) {
437463
[self sendTags:tagsToSend];
464+
[self sendLocation:lastLocation];
438465
tagsToSend = nil;
439466
}
440467

@@ -1147,6 +1174,64 @@ - (void)processLocalActionBasedNotification:(UILocalNotification*) notification
11471174
}
11481175
}
11491176

1177+
- (void) promptLocation {
1178+
[OneSignalLocation getLocation:self prompt:true];
1179+
}
1180+
1181+
1182+
- (void)locationManager:(id)manager didUpdateLocations:(NSArray*)locations {
1183+
[manager performSelector:@selector(stopUpdatingLocation)];
1184+
1185+
if (location_event_fired)
1186+
return;
1187+
1188+
location_event_fired = true;
1189+
1190+
id location = locations.lastObject;
1191+
1192+
SEL cord_selector = NSSelectorFromString(@"coordinate");
1193+
os_location_coordinate cords;
1194+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[location class] instanceMethodSignatureForSelector:cord_selector]];
1195+
1196+
[invocation setTarget:locations.lastObject];
1197+
[invocation setSelector:cord_selector];
1198+
[invocation invoke];
1199+
[invocation getReturnValue:&cords];
1200+
1201+
os_last_location *currentLocation = (os_last_location*)malloc(sizeof(os_last_location));
1202+
currentLocation->verticalAccuracy = [[location valueForKey:@"verticalAccuracy"] doubleValue];
1203+
currentLocation->horizontalAccuracy = [[location valueForKey:@"horizontalAccuracy"] doubleValue];
1204+
currentLocation->cords = cords;
1205+
1206+
if (mUserId == nil) {
1207+
lastLocation = currentLocation;
1208+
return;
1209+
}
1210+
1211+
[self sendLocation:currentLocation];
1212+
}
1213+
1214+
- (void) sendLocation:(os_last_location*)location {
1215+
1216+
NSMutableURLRequest* request = [self.httpClient requestWithMethod:@"PUT" path:[NSString stringWithFormat:@"players/%@", mUserId]];
1217+
1218+
NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys:
1219+
self.app_id, @"app_id",
1220+
[NSNumber numberWithDouble:location->cords.latitude], @"lat",
1221+
[NSNumber numberWithDouble:location->cords.longitude], @"long",
1222+
[NSNumber numberWithDouble:location->verticalAccuracy], @"loc_acc_vert",
1223+
[NSNumber numberWithDouble:location->horizontalAccuracy], @"loc_acc",
1224+
getNetType(), @"net_type",
1225+
nil];
1226+
1227+
NSData* postData = [NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil];
1228+
[request setHTTPBody:postData];
1229+
1230+
[self enqueueRequest:request
1231+
onSuccess:nil
1232+
onFailure:nil];
1233+
}
1234+
11501235
@end
11511236

11521237

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2016 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#ifndef OneSignalLocation_h
29+
#define OneSignalLocation_h
30+
31+
@interface OneSignalLocation : NSObject
32+
+ (void) getLocation:(id)delegate prompt:(bool)prompt;
33+
@end
34+
35+
#endif /* OneSignalLocation_h */
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2016 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import <Foundation/Foundation.h>
29+
#import <UIKit/UIKit.h>
30+
31+
#import "OneSignalLocation.h"
32+
33+
@implementation OneSignalLocation
34+
35+
static id locationManager;
36+
static bool started = false;
37+
static bool hasDelayed = false;
38+
39+
// CoreLocation must be statically linked for geotagging to work on iOS 6 and possibly 7.
40+
// plist NSLocationUsageDescription (iOS 6 & 7) and NSLocationWhenInUseUsageDescription (iOS 8+) keys also required.
41+
42+
// Suppressing undeclared selector warnings
43+
// NSClassFromString and performSelector are used so OneSignal does not depend on CoreLocation to link the app.
44+
#pragma GCC diagnostic push
45+
#pragma GCC diagnostic ignored "-Wundeclared-selector"
46+
#pragma clang diagnostic push
47+
#pragma clang diagnostic ignored "-Wundeclared-selector"
48+
49+
+ (void) getLocation:(id)delegate prompt:(bool)prompt {
50+
if (hasDelayed)
51+
[OneSignalLocation internalGetLocation:delegate prompt:prompt];
52+
else {
53+
// Delay required for locationServicesEnabled and authorizationStatus return the correct values when CoreLocation is not staticly linked.
54+
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC);
55+
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
56+
hasDelayed = true;
57+
[OneSignalLocation internalGetLocation:delegate prompt:prompt];
58+
});
59+
}
60+
}
61+
62+
+ (void) internalGetLocation:(id)delegate prompt:(bool)prompt {
63+
NSLog(@"getLocation called:started:%d", started);
64+
if (started)
65+
return;
66+
67+
id clLocationManagerClass = NSClassFromString(@"CLLocationManager");
68+
69+
// Check for location in plist
70+
if (![clLocationManagerClass performSelector:@selector(locationServicesEnabled)])
71+
return;
72+
73+
if ([clLocationManagerClass performSelector:@selector(authorizationStatus)] == 0 && !prompt)
74+
return;
75+
76+
locationManager = [[clLocationManagerClass alloc] init];
77+
[locationManager setValue:delegate forKey:@"delegate"];
78+
//locationManager.distanceFilter = kCLDistanceFilterNone;
79+
//locationManager.desiredAccuracy = kCLLocationAccuracyBest;
80+
81+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
82+
[locationManager performSelector:@selector(requestWhenInUseAuthorization)];
83+
84+
// iOS 6 and 7 prompts for location here.
85+
[locationManager performSelector:@selector(startUpdatingLocation)];
86+
87+
started = true;
88+
}
89+
90+
#pragma clang diagnostic pop
91+
#pragma GCC diagnostic pop
92+
93+
@end

0 commit comments

Comments
 (0)