Skip to content

Commit 792c661

Browse files
committed
Remove null pushToken check for notification_types
* We should always update notification_types so it is the most accurate value. - pushToken should not be a factor on if we should update notification_types - This logic was here from day one https://github.com/OneSignal/OneSignal-iOS-SDK/blame/85a9351a144c36c9af2206cd3ec80e1abab005c2/iOS_SDK/OneSignalSDK/Source/OneSignal.m#L1636 * Also fixed the testNotAcceptingNotificationsWithoutBackgroundModes flaky test - Updated it to account for the new notification_types logic.
1 parent 380f40f commit 792c661

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,7 @@ + (void)updateNotificationTypes:(int)notificationTypes {
21922192

21932193
if (!startedRegister && [self shouldRegisterNow])
21942194
[OneSignal registerUser];
2195-
else if (self.currentSubscriptionState.pushToken)
2195+
else
21962196
[self sendNotificationTypesUpdate];
21972197

21982198
if ([self getUsableDeviceToken])

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,16 +899,21 @@ - (void)testNotAcceptingNotificationsWithoutBackgroundModes {
899899
[self backgroundModesDisabledInXcode];
900900

901901
[UnitTestCommonMethods initOneSignal];
902-
// Don't make a network call right away
902+
// Testing network call is not being made from the main thread.
903903
XCTAssertNil(OneSignalClientOverrider.lastHTTPRequest);
904904

905-
[UnitTestCommonMethods answerNotificationPrompt:false];
905+
// Run pending player create call, notification_types should never answnser prompt
906906
[UnitTestCommonMethods runBackgroundThreads];
907-
908907
XCTAssertEqualObjects(OneSignalClientOverrider.lastUrl, serverUrlWithPath(@"players"));
909908
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"app_id"], @"b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
910909
XCTAssertNil(OneSignalClientOverrider.lastHTTPRequest[@"identifier"]);
911-
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @0);
910+
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @(ERROR_PUSH_PROMPT_NEVER_ANSWERED));
911+
912+
// Ensure we make an PUT call to update to notification_types declined
913+
[UnitTestCommonMethods answerNotificationPrompt:false];
914+
[UnitTestCommonMethods runBackgroundThreads];
915+
XCTAssertEqualObjects(OneSignalClientOverrider.lastUrl, serverUrlWithPath(@"players/1234"));
916+
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @(NOTIFICATION_TYPE_NONE));
912917
}
913918

914919
- (void)testIdsAvailableNotAcceptingNotifications {

0 commit comments

Comments
 (0)