Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't wait for push prompt to register user #990

Merged
merged 2 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -1631,18 +1631,10 @@ + (void)updateDeviceToken:(NSString*)deviceToken {
let isPushTokenDifferent = ![deviceToken isEqualToString:self.currentSubscriptionState.pushToken];
self.currentSubscriptionState.pushToken = deviceToken;

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

+ (void)playerPutForPushTokenAndNotificationTypes {
Expand Down
2 changes: 1 addition & 1 deletion iOS_SDK/OneSignalSDK/UnitTests/MigrationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ - (void)testIAMCachedDictionaryToCachedCodeableMigration {

NSDictionary<NSString *, OSInAppMessageInternal *>*retrievedDict = [OneSignalUserDefaults.initStandard
getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:nil];
XCTAssertEqualObjects(emptyDict, retrievedDict);
XCTAssertEqualObjects(nil, retrievedDict);
}

- (void)testIAMCachedCodeableMigration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ + (void)load {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
injectToProperClass(@selector(overrideAnimateAppearance), @selector(animateAppearance), @[], [OSInAppMessageViewControllerOverrider class], [OSInAppMessageViewController class]);
injectToProperClass(@selector(overrideAnimateAppearance:), @selector(animateAppearance:), @[], [OSInAppMessageViewControllerOverrider class], [OSInAppMessageViewController class]);
#pragma clang diagnostic pop
}

- (void)overrideAnimateAppearance {

}

- (void)overrideAnimateAppearance:(BOOL)firstDisplay {

}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)resetState;
- (void)messageViewDidSelectAction:(OSInAppMessageInternal *)message withAction:(OSInAppMessageAction *)action;
- (void)persistInAppMessageForRedisplay:(OSInAppMessageInternal *)message;
- (void)messageViewControllerWasDismissed;
- (void)messageViewControllerWasDismissed:(OSInAppMessageInternal *)message displayed:(BOOL)displayed;
- (void)setLastTimeGenerator:(NSTimeInterval(^)(void))dateGenerator;
- (NSArray<OSInAppMessageInternal *> *)getInAppMessages;
- (NSMutableDictionary <NSString *, OSInAppMessageInternal *> *)getRedisplayedInAppMessages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ + (void)load {

- (void)overrideShowMessage:(OSInAppMessageInternal *)message {
dispatch_async(dispatch_get_main_queue(), ^{
let viewController = [[OSInAppMessageViewController alloc] initWithMessage:message delegate:OSMessagingController.self];
let viewController = [[OSInAppMessageViewController alloc] initWithMessage:message delegate:OSMessagingController.sharedInstance];
[viewController viewDidLoad];
[OSMessagingController.sharedInstance webViewContentFinishedLoading:message];
});
Expand All @@ -107,7 +107,7 @@ - (void)overrideWebViewContentFinishedLoading:(OSInAppMessageInternal *)message
}

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

+ (BOOL)isInAppMessageShowing {
Expand Down
17 changes: 6 additions & 11 deletions iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -698,16 +698,12 @@ - (void)testPromptForPushNotificationsWithUserResponseOnIOS9 {
XCTAssertTrue(didAccept);
}

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

// Don't make a network call right away
XCTAssertNil(OneSignalClientOverrider.lastHTTPRequest);

// Triggers the 30 fallback to register device right away.
[OneSignal performSelector:NSSelectorFromString(@"registerUser")];
[UnitTestCommonMethods runBackgroundThreads];

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

- (void)testSendTagsBeforeRegisterComplete {
[UnitTestCommonMethods setCurrentNotificationPermissionAsUnanswered];
[UnitTestCommonMethods initOneSignal];
[OneSignal sendTag:@"key" value:@"value"];
[UnitTestCommonMethods foregroundApp];
[UnitTestCommonMethods runBackgroundThreads];

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

[OneSignal sendTag:@"key" value:@"value"];

[UnitTestCommonMethods runBackgroundThreads];

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

[UnitTestCommonMethods answerNotificationPrompt:false];
[UnitTestCommonMethods initOneSignal];
[UnitTestCommonMethods runBackgroundThreads];

// A single POST player create call should be made with tags included.
XCTAssertEqual(OneSignalClientOverrider.networkRequestCount, 2);
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"tags"][@"key"], @"value");
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @0);
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @15);
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"identifier"], @"0000000000000000000000000000000000000000000000000000000000000000");
}

Expand Down