Skip to content

Commit 2c02026

Browse files
author
Joseph Kalash
committed
- OneSignal will now detect and show an error message for 'No Push Token' issues when the Push Notification capability is not enabled for the app target.
- Fixed an iOS 10 issue where silent notifications fail to load properly when the app is in the foreground. - Fixed a 'No Push Token' issue in 2.1.10 that would happen when OneSignal was downloaded through CocoaPods and included other pods that used the -ObjC flag.
1 parent 7e7f6f8 commit 2c02026

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
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.1.10"
3+
s.version = "2.1.11"
44
s.summary = "OneSignal push notification library for mobile apps."
55
s.homepage = "https://onesignal.com"
66
s.license = { :type => 'MIT', :file => 'LICENSE' }
-489 KB
Binary file not shown.

iOS_SDK/OneSignal/OneSignal.m

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

48-
#import "UIApplication+Swizzling.m"
49-
5048
#define NOTIFICATION_TYPE_NONE 0
5149
#define NOTIFICATION_TYPE_BADGE 1
5250
#define NOTIFICATION_TYPE_SOUND 2
5351
#define NOTIFICATION_TYPE_ALERT 4
5452
#define NOTIFICATION_TYPE_ALL 7
5553

54+
#define ERROR_PUSH_CAPABLILITY_DISABLED -13
55+
5656
#pragma clang diagnostic push
5757
#pragma clang diagnostic ignored "-Wundeclared-selector"
5858

@@ -75,7 +75,7 @@
7575

7676
@implementation OneSignal
7777

78-
NSString* const ONESIGNAL_VERSION = @"020110";
78+
NSString* const ONESIGNAL_VERSION = @"020111";
7979
static NSString* mSDKType = @"native";
8080
static BOOL coldStartFromTapOnNotification = NO;
8181
static BOOL registeredWithApple = NO; //Has attempted to register for push notifications with Apple.
@@ -719,6 +719,10 @@ + (void)registerUser {
719719
if (mDeviceToken)
720720
idsAvailableBlockWhenReady = nil;
721721
}
722+
723+
//If we got a userId after the notificationTypes were set to error -13, update server
724+
if(mNotificationTypes == ERROR_PUSH_CAPABLILITY_DISABLED)
725+
[self setErrorNotificationType];
722726
}
723727
} onFailure:^(NSError* error) {
724728
waitingForOneSReg = false;
@@ -740,12 +744,10 @@ + (void) sendNotificationTypesUpdate:(BOOL)isNewType {
740744
if (mNotificationTypes != -1 && mUserId && (isNewType || mNotificationTypes != [self getNotificationTypes])) {
741745
mNotificationTypes = [self getNotificationTypes];
742746
NSMutableURLRequest* request = [httpClient requestWithMethod:@"PUT" path:[NSString stringWithFormat:@"players/%@", mUserId]];
743-
744747
NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys:
745748
app_id, @"app_id",
746-
[NSNumber numberWithInt:mNotificationTypes], @"notification_types",
749+
@(mNotificationTypes), @"notification_types",
747750
nil];
748-
749751
NSData* postData = [NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil];
750752
[request setHTTPBody:postData];
751753

@@ -938,8 +940,12 @@ + (BOOL) clearBadgeCount:(BOOL)fromNotifOpened {
938940
}
939941

940942
+ (int) getNotificationTypes {
943+
944+
if(mNotificationTypes == ERROR_PUSH_CAPABLILITY_DISABLED)
945+
return mNotificationTypes;
946+
941947
if (!mSubscriptionSet)
942-
return -2;
948+
return -2;
943949

944950
if (mDeviceToken) {
945951
if ([OneSignalHelper isCapableOfGettingNotificationTypes])
@@ -951,6 +957,22 @@ + (int) getNotificationTypes {
951957
return -1;
952958
}
953959

960+
+ (void)setErrorNotificationType {
961+
mNotificationTypes = ERROR_PUSH_CAPABLILITY_DISABLED;
962+
963+
if([self mUserId]) {
964+
NSMutableURLRequest* request = [httpClient requestWithMethod:@"PUT" path:[NSString stringWithFormat:@"players/%@", mUserId]];
965+
NSDictionary* dataDic = [NSDictionary dictionaryWithObjectsAndKeys:
966+
app_id, @"app_id",
967+
@(mNotificationTypes), @"notification_types",
968+
nil];
969+
NSData* postData = [NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil];
970+
[request setHTTPBody:postData];
971+
972+
[OneSignalHelper enqueueRequest:request onSuccess:nil onFailure:nil];
973+
}
974+
}
975+
954976
// iOS 8.0+ only
955977
+ (void) updateNotificationTypes:(int)notificationTypes {
956978

iOS_SDK/OneSignal/UIApplication+Swizzling.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ + (void) remoteSilentNotification:(UIApplication*)application UserInfo:(NSDictio
122122
+ (void) updateNotificationTypes:(int)notificationTypes;
123123
+ (void) notificationOpened:(NSDictionary*)messageDict isActive:(BOOL)isActive;
124124
+ (void) processLocalActionBasedNotification:(UILocalNotification*) notification identifier:(NSString*)identifier;
125+
+ (void) setErrorNotificationType;
125126
@end
126127

127128
@interface OneSignalTracker ()
@@ -150,7 +151,13 @@ - (void)oneSignalDidRegisterForRemoteNotifications:(UIApplication*)app deviceTok
150151

151152
- (void)oneSignalDidFailRegisterForRemoteNotification:(UIApplication*)app error:(NSError*)err {
152153

153-
if([OneSignal app_id])
154+
if(err.code == 3000 && [(NSString*)[err.userInfo objectForKey:NSLocalizedDescriptionKey] containsString:@"no valid 'aps-environment'"]) {
155+
//User did not enable push notification capability
156+
[OneSignal setErrorNotificationType];
157+
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:@"'Push Notification' capability not turned on. Make sure it is enabled by going to your Project Target -> Capability."];
158+
}
159+
160+
else if([OneSignal app_id])
154161
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:[NSString stringWithFormat: @"Error registering for Apple push notifications. Error: %@", err]];
155162

156163
if ([self respondsToSelector:@selector(oneSignalDidFailRegisterForRemoteNotification:error:)])
@@ -184,7 +191,7 @@ - (void) oneSignalRemoteSilentNotification:(UIApplication*)application UserInfo:
184191

185192
//Call notificationAction if app is active -> not a silent notification but rather user tap on notification
186193
//Unless iOS 10+ then call remoteSilentNotification instead.
187-
if([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
194+
if([UIApplication sharedApplication].applicationState == UIApplicationStateActive && userInfo[@"aps"][@"alert"])
188195
[OneSignal notificationOpened:userInfo isActive:YES];
189196
else [OneSignal remoteSilentNotification:application UserInfo:userInfo];
190197

0 commit comments

Comments
 (0)