Skip to content

Commit 3672cc2

Browse files
authored
Merge pull request #990 from OneSignal/fix/register_user_immediately_after_apns
Don't wait for push prompt to register user
2 parents c98b1f8 + 66b3d4f commit 3672cc2

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,18 +1631,10 @@ + (void)updateDeviceToken:(NSString*)deviceToken {
16311631
let isPushTokenDifferent = ![deviceToken isEqualToString:self.currentSubscriptionState.pushToken];
16321632
self.currentSubscriptionState.pushToken = deviceToken;
16331633

1634-
// iOS 9+ - We get a token right away but give the user 30 sec to respond notification permission prompt.
1635-
// The goal is to only have 1 server call.
1636-
[self.osNotificationSettings getNotificationPermissionState:^(OSPermissionState *status) {
1637-
if (status.answeredPrompt || status.provisional) {
1638-
if ([self shouldRegisterNow])
1639-
[self registerUser];
1640-
else if (isPushTokenDifferent)
1641-
[self playerPutForPushTokenAndNotificationTypes];
1642-
} else {
1643-
[self registerUserAfterDelay];
1644-
}
1645-
}];
1634+
if ([self shouldRegisterNow])
1635+
[self registerUser];
1636+
else if (isPushTokenDifferent)
1637+
[self playerPutForPushTokenAndNotificationTypes];
16461638
}
16471639

16481640
+ (void)playerPutForPushTokenAndNotificationTypes {

iOS_SDK/OneSignalSDK/UnitTests/MigrationTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ - (void)testIAMCachedDictionaryToCachedCodeableMigration {
257257

258258
NSDictionary<NSString *, OSInAppMessageInternal *>*retrievedDict = [OneSignalUserDefaults.initStandard
259259
getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:nil];
260-
XCTAssertEqualObjects(emptyDict, retrievedDict);
260+
XCTAssertEqualObjects(nil, retrievedDict);
261261
}
262262

263263
- (void)testIAMCachedCodeableMigration {

iOS_SDK/OneSignalSDK/UnitTests/Shadows/OSInAppMessageViewControllerOverrider.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ + (void)load {
3636
#pragma clang diagnostic push
3737
#pragma clang diagnostic ignored "-Wundeclared-selector"
3838
injectToProperClass(@selector(overrideAnimateAppearance), @selector(animateAppearance), @[], [OSInAppMessageViewControllerOverrider class], [OSInAppMessageViewController class]);
39+
injectToProperClass(@selector(overrideAnimateAppearance:), @selector(animateAppearance:), @[], [OSInAppMessageViewControllerOverrider class], [OSInAppMessageViewController class]);
3940
#pragma clang diagnostic pop
4041
}
4142

4243
- (void)overrideAnimateAppearance {
4344

4445
}
4546

47+
- (void)overrideAnimateAppearance:(BOOL)firstDisplay {
48+
49+
}
50+
4651
@end

iOS_SDK/OneSignalSDK/UnitTests/Shadows/OSMessagingControllerOverrider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
4848
- (void)resetState;
4949
- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageAction *)action;
5050
- (void)persistInAppMessageForRedisplay:(OSInAppMessageInternal *)message;
51-
- (void)messageViewControllerWasDismissed;
51+
- (void)messageViewControllerWasDismissed:(OSInAppMessageInternal *)message displayed:(BOOL)displayed;
5252
- (void)setLastTimeGenerator:(NSTimeInterval(^)(void))dateGenerator;
5353
- (NSArray<OSInAppMessageInternal *> *)getInAppMessages;
5454
- (NSMutableDictionary <NSString *, OSInAppMessageInternal *> *)getRedisplayedInAppMessages;

iOS_SDK/OneSignalSDK/UnitTests/Shadows/OSMessagingControllerOverrider.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ + (void)load {
9494

9595
- (void)overrideShowMessage:(OSInAppMessageInternal *)message {
9696
dispatch_async(dispatch_get_main_queue(), ^{
97-
let viewController = [[OSInAppMessageViewController alloc] initWithMessage:message delegate:OSMessagingController.self];
97+
let viewController = [[OSInAppMessageViewController alloc] initWithMessage:message delegate:OSMessagingController.sharedInstance];
9898
[viewController viewDidLoad];
9999
[OSMessagingController.sharedInstance webViewContentFinishedLoading:message];
100100
});
@@ -107,7 +107,7 @@ - (void)overrideWebViewContentFinishedLoading:(OSInAppMessageInternal *)message
107107
}
108108

109109
+ (void)dismissCurrentMessage {
110-
[OSMessagingController.sharedInstance messageViewControllerWasDismissed];
110+
[OSMessagingController.sharedInstance messageViewControllerWasDismissed: self.messageDisplayQueue.firstObject displayed:YES];
111111
}
112112

113113
+ (BOOL)isInAppMessageShowing {

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -698,16 +698,12 @@ - (void)testPromptForPushNotificationsWithUserResponseOnIOS9 {
698698
XCTAssertTrue(didAccept);
699699
}
700700

701+
// We should always register right away regardless of notification prompt status
701702
- (void)testPromptedButNeveranswerNotificationPrompt {
702703
[UnitTestCommonMethods setCurrentNotificationPermissionAsUnanswered];
703704
[OneSignal promptForPushNotificationsWithUserResponse:nil];
704705
[UnitTestCommonMethods initOneSignal_andThreadWait];
705706

706-
// Don't make a network call right away
707-
XCTAssertNil(OneSignalClientOverrider.lastHTTPRequest);
708-
709-
// Triggers the 30 fallback to register device right away.
710-
[OneSignal performSelector:NSSelectorFromString(@"registerUser")];
711707
[UnitTestCommonMethods runBackgroundThreads];
712708

713709
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"app_id"], @"b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
@@ -1498,26 +1494,25 @@ - (void)testGetTagsWithNestedDelete {
14981494
}
14991495

15001496
- (void)testSendTagsBeforeRegisterComplete {
1501-
[UnitTestCommonMethods setCurrentNotificationPermissionAsUnanswered];
1502-
[UnitTestCommonMethods initOneSignal];
1497+
[OneSignal sendTag:@"key" value:@"value"];
15031498
[UnitTestCommonMethods foregroundApp];
15041499
[UnitTestCommonMethods runBackgroundThreads];
15051500

15061501
NSObjectOverrider.selectorNamesForInstantOnlyForFirstRun = [@[@"sendTagsToServer"] mutableCopy];
15071502

1508-
[OneSignal sendTag:@"key" value:@"value"];
1503+
15091504
[UnitTestCommonMethods runBackgroundThreads];
15101505

15111506
// Do not try to send tag update yet as there isn't a player_id yet.
1512-
XCTAssertEqual(OneSignalClientOverrider.networkRequestCount, 1);
1507+
XCTAssertEqual(OneSignalClientOverrider.networkRequestCount, 0);
15131508

1514-
[UnitTestCommonMethods answerNotificationPrompt:false];
1509+
[UnitTestCommonMethods initOneSignal];
15151510
[UnitTestCommonMethods runBackgroundThreads];
15161511

15171512
// A single POST player create call should be made with tags included.
15181513
XCTAssertEqual(OneSignalClientOverrider.networkRequestCount, 2);
15191514
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"tags"][@"key"], @"value");
1520-
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @0);
1515+
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @15);
15211516
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"identifier"], @"0000000000000000000000000000000000000000000000000000000000000000");
15221517
}
15231518

0 commit comments

Comments
 (0)