Skip to content

Commit

Permalink
- Swizzling checks for all AppDelegate subclasses to find which prope…
Browse files Browse the repository at this point in the history
…r class to inject to. SDK makes sure the subclass overrides the required method and does not simply inherit it from a superclass.

- SDK parses info.plist to find out if it should request location when in use or always, or log an error if neither description entries are in the property list file.
- Changed CLLocationManagerDelegate from OneSignal’s private shared instance to the existing OneSignalLocation private singleton.
- Time-based location tracking. SDK sends user’s initial location then assigns a refresh rate of 5 min (foreground) or 10min (background).
  • Loading branch information
Joseph Kalash committed Aug 19, 2016
1 parent 86ad645 commit d4daa99
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 126 deletions.
2 changes: 1 addition & 1 deletion OneSignal.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "OneSignal"
s.version = "2.0.9"
s.version = "2.0.10"
s.summary = "OneSignal push notification library for mobile apps."
s.homepage = "https://onesignal.com"
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
Binary file modified iOS_SDK/Framework/OneSignal.framework/Versions/A/OneSignal
Binary file not shown.
Binary file modified iOS_SDK/Framework/OneSignal.framework/Versions/B/OneSignal
Binary file not shown.
95 changes: 11 additions & 84 deletions iOS_SDK/OneSignal/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

typedef struct os_location_coordinate {
double latitude;
double longitude;
} os_location_coordinate;

typedef struct os_last_location {
os_location_coordinate cords;
double verticalAccuracy;
double horizontalAccuracy;
} os_last_location;

static ONE_S_LOG_LEVEL _nsLogLevel = ONE_S_LL_WARN;
static ONE_S_LOG_LEVEL _visualLogLevel = ONE_S_LL_NONE;

Expand All @@ -82,15 +71,13 @@

@implementation OneSignal

NSString* const ONESIGNAL_VERSION = @"020009";
NSString* const ONESIGNAL_VERSION = @"020010";

static bool registeredWithApple = false; //Has attempted to register for push notifications with Apple.
static OneSignalTrackIAP* trackIAPPurchase;
static NSString* app_id;
NSString* emailToSet;
NSMutableDictionary* tagsToSend;
os_last_location *lastLocation;
BOOL location_event_fired;
NSString* mUserId;
NSString* mDeviceToken;
OneSignalHTTPClient *httpClient;
Expand Down Expand Up @@ -132,7 +119,7 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId
if ([@"b2f7f966-d8cc-11eg-bed1-df8f05be55ba" isEqualToString:appId] || [@"5eb5a37e-b458-11e3-ac11-000c2940e62c" isEqualToString:appId])
onesignal_Log(ONE_S_LL_WARN, @"OneSignal Example AppID detected, please update to your app's id found on OneSignal.com");

[OneSignalLocation getLocation:[OneSignalHelper sharedInstance] prompt:false];
[OneSignalLocation getLocation:false];

if (self) {

Expand Down Expand Up @@ -483,7 +470,7 @@ + (void)setSubscription:(BOOL)enable {
}

+ (void) promptLocation {
[OneSignalLocation getLocation:[OneSignalHelper sharedInstance] prompt:true];
[OneSignalLocation getLocation:true];
}

+ (void)registerDeviceToken:(id)inDeviceToken onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
Expand Down Expand Up @@ -642,12 +629,12 @@ + (void)registerUser {
NSData* postData = [NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil];
[request setHTTPBody:postData];

if (lastLocation) {
dataDic[@"lat"] = [NSNumber numberWithDouble:lastLocation->cords.latitude];
dataDic[@"long"] = [NSNumber numberWithDouble:lastLocation->cords.longitude];
dataDic[@"loc_acc_vert"] = [NSNumber numberWithDouble:lastLocation->verticalAccuracy];
dataDic[@"loc_acc"] = [NSNumber numberWithDouble:lastLocation->horizontalAccuracy];
lastLocation = nil;
if ([OneSignalLocation lastLocation]) {
dataDic[@"lat"] = [NSNumber numberWithDouble:[OneSignalLocation lastLocation]->cords.latitude];
dataDic[@"long"] = [NSNumber numberWithDouble:[OneSignalLocation lastLocation]->cords.longitude];
dataDic[@"loc_acc_vert"] = [NSNumber numberWithDouble:[OneSignalLocation lastLocation]->verticalAccuracy];
dataDic[@"loc_acc"] = [NSNumber numberWithDouble:[OneSignalLocation lastLocation]->horizontalAccuracy];
[OneSignalLocation clearLastLocation];
}

[OneSignalHelper enqueueRequest:request onSuccess:^(NSDictionary* results) {
Expand All @@ -672,10 +659,8 @@ + (void)registerUser {
tagsToSend = nil;
}

if (lastLocation) {
[self sendLocation:lastLocation];
lastLocation = nil;
}
//try to send location
[OneSignalLocation sendLocation];

if (emailToSet) {
[OneSignal syncHashedEmail:emailToSet];
Expand Down Expand Up @@ -1038,64 +1023,6 @@ + (void)processLocalActionBasedNotification:(UILocalNotification*) notification

}


- (void)locationManager:(id)manager didUpdateLocations:(NSArray *)locations {

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
[manager performSelector:@selector(stopUpdatingLocation)];
#pragma clang diagnostic pop

if (location_event_fired)
return;

location_event_fired = true;

id location = locations.lastObject;

SEL cord_selector = NSSelectorFromString(@"coordinate");
os_location_coordinate cords;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[location class] instanceMethodSignatureForSelector:cord_selector]];

[invocation setTarget:locations.lastObject];
[invocation setSelector:cord_selector];
[invocation invoke];
[invocation getReturnValue:&cords];

os_last_location *currentLocation = (os_last_location*)malloc(sizeof(os_last_location));
currentLocation->verticalAccuracy = [[location valueForKey:@"verticalAccuracy"] doubleValue];
currentLocation->horizontalAccuracy = [[location valueForKey:@"horizontalAccuracy"] doubleValue];
currentLocation->cords = cords;

if (mUserId == nil) {
lastLocation = currentLocation;
return;
}

[OneSignal sendLocation:currentLocation];
}

+ (void) sendLocation:(os_last_location*)location {

NSMutableURLRequest* request = [httpClient requestWithMethod:@"PUT" path:[NSString stringWithFormat:@"players/%@", mUserId]];

NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys:
app_id, @"app_id",
[NSNumber numberWithDouble:location->cords.latitude], @"lat",
[NSNumber numberWithDouble:location->cords.longitude], @"long",
[NSNumber numberWithDouble:location->verticalAccuracy], @"loc_acc_vert",
[NSNumber numberWithDouble:location->horizontalAccuracy], @"loc_acc",
[OneSignalHelper getNetType], @"net_type",
nil];

NSData* postData = [NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil];
[request setHTTPBody:postData];

[OneSignalHelper enqueueRequest:request
onSuccess:nil
onFailure:nil];
}

#if XC8_AVAILABLE

static id<OSUserNotificationCenterDelegate> notificationCenterDelegate;
Expand Down
3 changes: 0 additions & 3 deletions iOS_SDK/OneSignal/OneSignalHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
// - Web
+ (void) displayWebView:(NSURL*)url;

// - Visible Shareds Instance
+ (OneSignal*) sharedInstance;

// - Notification Opened
+ (NSArray<NSString*>*)getPushTitleBody:(NSDictionary*)messageDict;
+ (NSArray*)getActionButtons;
Expand Down
1 change: 0 additions & 1 deletion iOS_SDK/OneSignal/OneSignalHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ + (id)prepareUNNotificationRequest:(NSDictionary *)data :(NSDictionary *)userInf
//Check if media attached
//!! TEMP : Until Server implements Media Dict, use additional data dict as key val media
NSMutableArray *attachments = [NSMutableArray new];

NSDictionary * att = userInfo[@"custom"][@"at"];
if(!attachments)
attachments = userInfo[@"os_data"][@"at"];
Expand Down
19 changes: 18 additions & 1 deletion iOS_SDK/OneSignal/OneSignalLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,25 @@
#ifndef OneSignalLocation_h
#define OneSignalLocation_h

typedef struct os_location_coordinate {
double latitude;
double longitude;
} os_location_coordinate;

typedef struct os_last_location {
os_location_coordinate cords;
double verticalAccuracy;
double horizontalAccuracy;
} os_last_location;


@interface OneSignalLocation : NSObject
+ (void) getLocation:(id)delegate prompt:(bool)prompt;
+ (void) getLocation:(bool)prompt;
+ (void) sendLocation;
+ (os_last_location*)lastLocation;
+ (void)clearLastLocation;
+ (void)onfocus:(BOOL)isActive;

@end

#endif /* OneSignalLocation_h */
Loading

0 comments on commit d4daa99

Please sign in to comment.