Skip to content

Commit 7e3adf1

Browse files
committed
Read playerId and appId from OSResilientStorage in NSE if needed
1 parent d56f008 commit 7e3adf1

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#import <OneSignalCore/OneSignalCore.h>
29+
#import <OneSignalOSCore/OneSignalOSCore-Swift.h>
2930
#import "OSMacros.h"
3031
#import <OneSignalOutcomes/OneSignalOutcomes.h>
3132
#import "OneSignalNotificationServiceExtensionHandler.h"
@@ -141,8 +142,19 @@ + (void)onNotificationReceived:(NSString *)receivedNotificationId withBlockingTa
141142

142143
// Track confirmed delivery
143144
let sharedUserDefaults = OneSignalUserDefaults.initShared;
144-
let playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil];
145-
let appId = [sharedUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil];
145+
NSString *playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil];
146+
NSString *appId = [sharedUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil];
147+
148+
// Fall back to the unencrypted cache if UserDefaults reads return nil.
149+
// This handles cases where the NSE runs while the device is locked and the
150+
// UserDefaults file (NSFileProtectionCompleteUntilFirstUserAuthentication) is not readable.
151+
if (!playerId) {
152+
playerId = [OSResilientStorage stringForKey:OSResilientStorage.keySubscriptionId];
153+
}
154+
if (!appId) {
155+
appId = [OSResilientStorage stringForKey:OSResilientStorage.keyAppId];
156+
}
157+
146158
// Randomize send of confirmed deliveries to lessen traffic for high recipient notifications
147159
int randomDelay = semaphore != nil ? arc4random_uniform(MAX_CONF_DELIVERY_DELAY) : 0;
148160
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"OneSignal onNotificationReceived sendReceiveReceipt with delay: %i", randomDelay]];

0 commit comments

Comments
 (0)