Skip to content

Commit 19a14b0

Browse files
committed
- Updated OneSignal.h header explanation for the singleton class
- FIX: No more usableDeviceToken method. Explanation: This method used to return null thus not registering any push token if the user did not grant push permissions. Changed since dev can still send remoteSilent notifications. This also fixed the no push token issue developers where experiencing. - FIX: Remove call to registerForPushNotifications without prompt in init when autoPrompt set to false. Only communicate with APNS once dev calls registerForPushNotifications API. Fixes ambiguity when passing kOSSettingsKeyAutoPrompt : @no. - FIX: Ad Hoc profile no longer need to restart app to properly register token - FIX: Non-initializing the OneSignal SDK no longer blocks swizzled UIApplicationDelegate methods from getting called
1 parent 27043db commit 19a14b0

File tree

9 files changed

+136
-98
lines changed

9 files changed

+136
-98
lines changed

OneSignal.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "OneSignal"
3-
s.version = "2.0.8"
3+
s.version = "2.0.9"
44
s.summary = "OneSignal push notification library for mobile apps."
55
s.homepage = "https://onesignal.com"
66
s.license = { :type => 'MIT', :file => 'LICENSE' }

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
/***
29+
30+
### Setting up the SDK ###
31+
Follow the documentation from https://documentation.onesignal.com/docs/installing-the-onesignal-ios-sdk to setup OneSignal in your app.
32+
33+
### API Reference ###
34+
Follow the documentation from https://documentation.onesignal.com/docs/ios-sdk-api for a detailed explanation of the API.
35+
36+
### FAQ & Troubleshoot ###
37+
FAQ: https://documentation.onesignal.com/docs/frequently-asked-questions-1
38+
Troubleshoot: https://documentation.onesignal.com/docs/common-problems-1
39+
40+
For help on how to upgrade your code from 1.* SDK to 2.*: https://documentation.onesignal.com/docs/upgrading-to-sdk-20
41+
42+
### More ###
43+
iOS Configuration: https://documentation.onesignal.com/docs/generating-an-ios-push-certificate
44+
REST API: https://documentation.onesignal.com/docs/server-api-overview
45+
Create Notification API: https://documentation.onesignal.com/docs/notifications-create-notification
46+
47+
***/
48+
2849
#import <Foundation/Foundation.h>
2950

3051
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
@@ -158,17 +179,11 @@ extern NSString * const kOSSettingsKeyInAppAlerts;
158179
extern NSString * const kOSSettingsKeyInAppLaunchURL;
159180

160181
/**
161-
`OneSignal` provides a high level interface to interact with OneSignal's push service.
162-
163-
`OneSignal` exposes a defaultClient for applications which use a globally available client to share configuration settings.
164-
165-
Include `#import "OneSignal/OneSignal.h"` in your application files to access OneSignal's methods.
166-
167-
### Setting up the SDK ###
168-
169-
Follow the documentation from http://documentation.gamethrive.com/v1.0/docs/installing-the-gamethrive-ios-sdk to setup with your game.
170-
171-
*/
182+
OneSignal provides a high level interface to interact with OneSignal's push service.
183+
OneSignal is a singleton for applications which use a globally available client to share configuration settings.
184+
You should avoid creating instances of this class at all costs. Instead, access its instance methods.
185+
Include `#import <OneSignal/OneSignal.h>` in your application files to access OneSignal's methods.
186+
**/
172187
@interface OneSignal : NSObject
173188

174189
extern NSString* const ONESIGNAL_VERSION;
-26.5 KB
Binary file not shown.

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
/***
29+
30+
### Setting up the SDK ###
31+
Follow the documentation from https://documentation.onesignal.com/docs/installing-the-onesignal-ios-sdk to setup OneSignal in your app.
32+
33+
### API Reference ###
34+
Follow the documentation from https://documentation.onesignal.com/docs/ios-sdk-api for a detailed explanation of the API.
35+
36+
### FAQ & Troubleshoot ###
37+
FAQ: https://documentation.onesignal.com/docs/frequently-asked-questions-1
38+
Troubleshoot: https://documentation.onesignal.com/docs/common-problems-1
39+
40+
For help on how to upgrade your code from 1.* SDK to 2.*: https://documentation.onesignal.com/docs/upgrading-to-sdk-20
41+
42+
### More ###
43+
iOS Configuration: https://documentation.onesignal.com/docs/generating-an-ios-push-certificate
44+
REST API: https://documentation.onesignal.com/docs/server-api-overview
45+
Create Notification API: https://documentation.onesignal.com/docs/notifications-create-notification
46+
47+
***/
48+
2849
#import <Foundation/Foundation.h>
2950

3051
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
@@ -158,17 +179,11 @@ extern NSString * const kOSSettingsKeyInAppAlerts;
158179
extern NSString * const kOSSettingsKeyInAppLaunchURL;
159180

160181
/**
161-
`OneSignal` provides a high level interface to interact with OneSignal's push service.
162-
163-
`OneSignal` exposes a defaultClient for applications which use a globally available client to share configuration settings.
164-
165-
Include `#import "OneSignal/OneSignal.h"` in your application files to access OneSignal's methods.
166-
167-
### Setting up the SDK ###
168-
169-
Follow the documentation from http://documentation.gamethrive.com/v1.0/docs/installing-the-gamethrive-ios-sdk to setup with your game.
170-
171-
*/
182+
OneSignal provides a high level interface to interact with OneSignal's push service.
183+
OneSignal is a singleton for applications which use a globally available client to share configuration settings.
184+
You should avoid creating instances of this class at all costs. Instead, access its instance methods.
185+
Include `#import <OneSignal/OneSignal.h>` in your application files to access OneSignal's methods.
186+
**/
172187
@interface OneSignal : NSObject
173188

174189
extern NSString* const ONESIGNAL_VERSION;
-26.6 KB
Binary file not shown.

iOS_SDK/OneSignal/OneSignal.h

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
/***
29+
30+
### Setting up the SDK ###
31+
Follow the documentation from https://documentation.onesignal.com/docs/installing-the-onesignal-ios-sdk to setup OneSignal in your app.
32+
33+
### API Reference ###
34+
Follow the documentation from https://documentation.onesignal.com/docs/ios-sdk-api for a detailed explanation of the API.
35+
36+
### FAQ & Troubleshoot ###
37+
FAQ: https://documentation.onesignal.com/docs/frequently-asked-questions-1
38+
Troubleshoot: https://documentation.onesignal.com/docs/common-problems-1
39+
40+
For help on how to upgrade your code from 1.* SDK to 2.*: https://documentation.onesignal.com/docs/upgrading-to-sdk-20
41+
42+
### More ###
43+
iOS Configuration: https://documentation.onesignal.com/docs/generating-an-ios-push-certificate
44+
REST API: https://documentation.onesignal.com/docs/server-api-overview
45+
Create Notification API: https://documentation.onesignal.com/docs/notifications-create-notification
46+
47+
***/
48+
2849
#import <Foundation/Foundation.h>
2950

3051
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
@@ -158,17 +179,11 @@ extern NSString * const kOSSettingsKeyInAppAlerts;
158179
extern NSString * const kOSSettingsKeyInAppLaunchURL;
159180

160181
/**
161-
`OneSignal` provides a high level interface to interact with OneSignal's push service.
162-
163-
`OneSignal` exposes a defaultClient for applications which use a globally available client to share configuration settings.
164-
165-
Include `#import "OneSignal/OneSignal.h"` in your application files to access OneSignal's methods.
166-
167-
### Setting up the SDK ###
168-
169-
Follow the documentation from http://documentation.gamethrive.com/v1.0/docs/installing-the-gamethrive-ios-sdk to setup with your game.
170-
171-
*/
182+
OneSignal provides a high level interface to interact with OneSignal's push service.
183+
OneSignal is a singleton for applications which use a globally available client to share configuration settings.
184+
You should avoid creating instances of this class at all costs. Instead, access its instance methods.
185+
Include `#import <OneSignal/OneSignal.h>` in your application files to access OneSignal's methods.
186+
**/
172187
@interface OneSignal : NSObject
173188

174189
extern NSString* const ONESIGNAL_VERSION;

iOS_SDK/OneSignal/OneSignal.m

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#import <sys/sysctl.h>
4646
#import <objc/runtime.h>
4747

48+
#define NOTIFICATION_TYPE_NONE 0
4849
#define NOTIFICATION_TYPE_BADGE 1
4950
#define NOTIFICATION_TYPE_SOUND 2
5051
#define NOTIFICATION_TYPE_ALERT 4
@@ -81,7 +82,7 @@
8182

8283
@implementation OneSignal
8384

84-
NSString* const ONESIGNAL_VERSION = @"020008";
85+
NSString* const ONESIGNAL_VERSION = @"020009";
8586

8687
static bool registeredWithApple = false; //Has attempted to register for push notifications with Apple.
8788
static OneSignalTrackIAP* trackIAPPurchase;
@@ -182,11 +183,6 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId
182183
if (autoPrompt || registeredWithApple)
183184
[self registerForPushNotifications];
184185

185-
186-
// iOS 8 - Register for remote notifications to get a token now since registerUserNotificationSettings is what shows the prompt.
187-
else if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)])
188-
[[UIApplication sharedApplication] registerForRemoteNotifications];
189-
190186
[OneSignalTracker onFocus:NO];
191187
}
192188

@@ -287,11 +283,13 @@ + (void)registerForPushNotifications {
287283
}
288284
}
289285

286+
//Block not assigned if userID nil and there is a device token
290287
+ (void)IdsAvailable:(OSIdsAvailableBlock)idsAvailableBlock {
288+
291289
if (mUserId)
292-
idsAvailableBlock(mUserId, [self getUsableDeviceToken]);
290+
idsAvailableBlock(mUserId, mDeviceToken);
293291

294-
if (mUserId == nil || [self getUsableDeviceToken] == nil)
292+
if (!mUserId || !mDeviceToken)
295293
idsAvailableBlockWhenReady = idsAvailableBlock;
296294
}
297295

@@ -476,7 +474,7 @@ + (void)setSubscription:(BOOL)enable {
476474

477475
mSubscriptionSet = enable;
478476

479-
[OneSignal sendNotificationTypesUpdateIsConfirmed:false];
477+
[OneSignal sendNotificationTypesUpdate:false];
480478
}
481479

482480
+ (void) promptLocation {
@@ -492,17 +490,20 @@ + (void)registerDeviceToken:(id)inDeviceToken onSuccess:(OSResultSuccessBlock)su
492490

493491
+ (void)updateDeviceToken:(NSString*)deviceToken onSuccess:(OSResultSuccessBlock)successBlock onFailure:(OSFailureBlock)failureBlock {
494492

493+
// Do not block next registration as there's a new token in hand
494+
nextRegistrationIsHighPriority = YES;
495+
495496
if (mUserId == nil) {
496497
mDeviceToken = deviceToken;
497498
tokenUpdateSuccessBlock = successBlock;
498499
tokenUpdateFailureBlock = failureBlock;
499500

500-
// iOS 8 - We get a token right away but give the user 20 sec to responsed to the system prompt.
501+
// iOS 8 - We get a token right away but give the user 10 sec to responsed to the system prompt.
501502
// Also check mNotificationTypes so there is no waiting if user has already answered the system prompt.
502503
// The goal is to only have 1 server call.
503504
if ([OneSignalHelper isCapableOfGettingNotificationTypes] && mNotificationTypes == -1) {
504505
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(registerUser) object:nil];
505-
[self performSelector:@selector(registerUser) withObject:nil afterDelay:20.0f];
506+
[self performSelector:@selector(registerUser) withObject:nil afterDelay:10.0f];
506507
}
507508
else
508509
[OneSignal registerUser];
@@ -534,17 +535,19 @@ + (void)updateDeviceToken:(NSString*)deviceToken onSuccess:(OSResultSuccessBlock
534535

535536
if (idsAvailableBlockWhenReady) {
536537
mNotificationTypes = [self getNotificationTypes];
537-
if ([self getUsableDeviceToken])
538-
idsAvailableBlockWhenReady(mUserId, [self getUsableDeviceToken]);
539-
idsAvailableBlockWhenReady = nil;
538+
if (mDeviceToken) {
539+
idsAvailableBlockWhenReady(mUserId, mDeviceToken);
540+
idsAvailableBlockWhenReady = nil;
541+
}
540542
}
543+
541544
}
542545

543-
//Set to yes whenever a high priority registration fails ... need to make the next one a high priority to disregard the 1 hour timer delay
546+
//Set to yes whenever a high priority registration fails ... need to make the next one a high priority to disregard the timer delay
544547
bool nextRegistrationIsHighPriority = NO;
545548

546549
+ (BOOL)isHighPriorityCall {
547-
return mUserId == nil || (mDeviceToken == nil && mNotificationTypes > 0) || nextRegistrationIsHighPriority;
550+
return mUserId == nil || (mDeviceToken == nil && mNotificationTypes > NOTIFICATION_TYPE_NONE) || nextRegistrationIsHighPriority;
548551
}
549552

550553
+(BOOL)shouldRegisterNow {
@@ -570,7 +573,6 @@ + (void)registerUser {
570573
if (waitingForOneSReg || ![self shouldRegisterNow])
571574
return;
572575

573-
574576
waitingForOneSReg = true;
575577

576578
NSMutableURLRequest* request;
@@ -676,9 +678,9 @@ + (void)registerUser {
676678
}
677679

678680
if (idsAvailableBlockWhenReady) {
679-
idsAvailableBlockWhenReady(mUserId, [self getUsableDeviceToken]);
680-
if ([self getUsableDeviceToken])
681-
idsAvailableBlockWhenReady = nil;
681+
idsAvailableBlockWhenReady(mUserId, mDeviceToken);
682+
if (mDeviceToken)
683+
idsAvailableBlockWhenReady = nil;
682684
}
683685
}
684686
} onFailure:^(NSError* error) {
@@ -689,16 +691,12 @@ + (void)registerUser {
689691
nextRegistrationIsHighPriority = YES;
690692
}];
691693
}
694+
695+
//Updates the server with the new user's notification Types
696+
+ (void) sendNotificationTypesUpdate:(BOOL)isNewType {
692697

693-
+(NSString*) getUsableDeviceToken {
694-
if (mNotificationTypes > 0)
695-
return mDeviceToken;
696-
return nil;
697-
}
698-
699-
+ (void) sendNotificationTypesUpdateIsConfirmed:(BOOL)isConfirm {
700698
// User changed notification settings for the app.
701-
if (mNotificationTypes != -1 && mUserId && (isConfirm || mNotificationTypes != [self getNotificationTypes])) {
699+
if (mNotificationTypes != -1 && mUserId && (isNewType || mNotificationTypes != [self getNotificationTypes])) {
702700
mNotificationTypes = [self getNotificationTypes];
703701
NSMutableURLRequest* request = [httpClient requestWithMethod:@"PUT" path:[NSString stringWithFormat:@"players/%@", mUserId]];
704702

@@ -712,8 +710,8 @@ + (void) sendNotificationTypesUpdateIsConfirmed:(BOOL)isConfirm {
712710

713711
[OneSignalHelper enqueueRequest:request onSuccess:nil onFailure:nil];
714712

715-
if ([self getUsableDeviceToken] && idsAvailableBlockWhenReady) {
716-
idsAvailableBlockWhenReady(mUserId, [self getUsableDeviceToken]);
713+
if (mDeviceToken && idsAvailableBlockWhenReady) {
714+
idsAvailableBlockWhenReady(mUserId, mDeviceToken);
717715
idsAvailableBlockWhenReady = nil;
718716
}
719717
}
@@ -910,20 +908,21 @@ + (int) getNotificationTypes {
910908

911909
// iOS 8.0+ only
912910
+ (void) updateNotificationTypes:(int)notificationTypes {
911+
913912
if (mNotificationTypes == -2)
914-
return;
913+
return;
915914

916915
BOOL changed = (mNotificationTypes != notificationTypes);
917916

918917
mNotificationTypes = notificationTypes;
919918

920-
if (mUserId == nil && mDeviceToken)
919+
if (!mUserId && mDeviceToken)
921920
[OneSignal registerUser];
922921
else if (mDeviceToken)
923-
[self sendNotificationTypesUpdateIsConfirmed:changed];
922+
[self sendNotificationTypesUpdate:changed];
924923

925-
if (idsAvailableBlockWhenReady && mUserId && [self getUsableDeviceToken])
926-
idsAvailableBlockWhenReady(mUserId, [self getUsableDeviceToken]);
924+
if (idsAvailableBlockWhenReady && mUserId && mDeviceToken)
925+
idsAvailableBlockWhenReady(mUserId, mDeviceToken);
927926
}
928927

929928
+ (void)didRegisterForRemoteNotifications:(UIApplication*)app deviceToken:(NSData*)inDeviceToken {

0 commit comments

Comments
 (0)