Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
3C448BA429381303002F96BC /* OneSignalNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C448BA329381303002F96BC /* OneSignalNotifications.framework */; };
3C448BA529381303002F96BC /* OneSignalNotifications.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3C448BA329381303002F96BC /* OneSignalNotifications.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3C5C6FED2FC902C600102E2C /* OneSignalOSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DE12F3F6289B2B7F002F63AA /* OneSignalOSCore.framework */; };
3C79A42C2DB2B3170097BC13 /* click.wav in Resources */ = {isa = PBXBuildFile; fileRef = 3C79A42A2DB2B3170097BC13 /* click.wav */; };
3C79A42D2DB2B3170097BC13 /* bark.wav in Resources */ = {isa = PBXBuildFile; fileRef = 3C79A4292DB2B3170097BC13 /* bark.wav */; };
4529DECC1FA7EAB800CEAB1D /* UserNotifications.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91B6EA051E83215000B5CF01 /* UserNotifications.framework */; };
Expand Down Expand Up @@ -293,6 +294,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3C5C6FED2FC902C600102E2C /* OneSignalOSCore.framework in Frameworks */,
CACBAAB7218A713C000ACAA5 /* WebKit.framework in Frameworks */,
DE97177A2756E6FF00FC409E /* OneSignalOutcomes.framework in Frameworks */,
91B6EA071E83215800B5CF01 /* UIKit.framework in Frameworks */,
Expand Down
47 changes: 47 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
3C5501402E09CF0100E77DF7 /* OSCopyOnWriteSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C55013E2E09CF0100E77DF7 /* OSCopyOnWriteSet.h */; };
3C5501412E09CF0100E77DF7 /* OSCopyOnWriteSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C55013F2E09CF0100E77DF7 /* OSCopyOnWriteSet.m */; };
3C5501432E09F3D900E77DF7 /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5501422E09F3D900E77DF7 /* LoggingTests.swift */; };
3C5C6FE72FC9008A00102E2C /* OSResilientStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5C6FE62FC9008A00102E2C /* OSResilientStorage.swift */; };
3C5C6FE82FC902A100102E2C /* OneSignalOSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C115161289A259500565C41 /* OneSignalOSCore.framework */; };
3C5C6FE92FC902A100102E2C /* OneSignalOSCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3C115161289A259500565C41 /* OneSignalOSCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3C5C6FF02FC903B900102E2C /* OneSignalOSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C115161289A259500565C41 /* OneSignalOSCore.framework */; };
3C60BB9B2ECF860600C765F7 /* OneSignalInAppMessages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; };
3C60BB9C2ECF860600C765F7 /* OneSignalInAppMessages.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3C62999F2BEEA34800649187 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C62999E2BEEA34800649187 /* PrivacyInfo.xcprivacy */; };
Expand Down Expand Up @@ -665,6 +669,20 @@
remoteGlobalIDString = 3C115160289A259500565C41;
remoteInfo = OneSignalOSCore;
};
3C5C6FEA2FC902A100102E2C /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 37747F8B19147D6400558FAD /* Project object */;
proxyType = 1;
remoteGlobalIDString = 3C115160289A259500565C41;
remoteInfo = OneSignalOSCore;
};
3C5C6FF22FC903B900102E2C /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 37747F8B19147D6400558FAD /* Project object */;
proxyType = 1;
remoteGlobalIDString = 3C115160289A259500565C41;
remoteInfo = OneSignalOSCore;
};
3C60BB9D2ECF860600C765F7 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 37747F8B19147D6400558FAD /* Project object */;
Expand Down Expand Up @@ -1147,6 +1165,17 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
3C5C6FEC2FC902A100102E2C /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
3C5C6FE92FC902A100102E2C /* OneSignalOSCore.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
3C60BB9F2ECF860600C765F7 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1330,6 +1359,7 @@
3C55013E2E09CF0100E77DF7 /* OSCopyOnWriteSet.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSCopyOnWriteSet.h; sourceTree = "<group>"; };
3C55013F2E09CF0100E77DF7 /* OSCopyOnWriteSet.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSCopyOnWriteSet.m; sourceTree = "<group>"; };
3C5501422E09F3D900E77DF7 /* LoggingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingTests.swift; sourceTree = "<group>"; };
3C5C6FE62FC9008A00102E2C /* OSResilientStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSResilientStorage.swift; sourceTree = "<group>"; };
3C62999E2BEEA34800649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
3C6299A02BEEA38100649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
3C6299A22BEEA3CC00649187 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1964,6 +1994,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3C5C6FE82FC902A100102E2C /* OneSignalOSCore.framework in Frameworks */,
DE7D1846270286C6002D3A5D /* OneSignalCore.framework in Frameworks */,
DE7D18D22703ADE0002D3A5D /* OneSignalOutcomes.framework in Frameworks */,
DE7D1843270283B9002D3A5D /* UserNotifications.framework in Frameworks */,
Expand Down Expand Up @@ -2048,6 +2079,7 @@
DEF7845F2912EA0D00A1F3A5 /* UserNotifications.framework in Frameworks */,
DEF784612912F5E100A1F3A5 /* UIKit.framework in Frameworks */,
DEF784422912E16F00A1F3A5 /* OneSignalCore.framework in Frameworks */,
3C5C6FF02FC903B900102E2C /* OneSignalOSCore.framework in Frameworks */,
DE2D8F4A2947D86200844084 /* OneSignalOutcomes.framework in Frameworks */,
DE2D8F452947D85800844084 /* OneSignalExtension.framework in Frameworks */,
);
Expand Down Expand Up @@ -2204,6 +2236,7 @@
3C115163289A259500565C41 /* OneSignalOSCore.h */,
3C115188289ADEA300565C41 /* OSModelStore.swift */,
3C115186289ADE7700565C41 /* OSModelStoreListener.swift */,
3C5C6FE62FC9008A00102E2C /* OSResilientStorage.swift */,
3C115184289ADE4F00565C41 /* OSModel.swift */,
3CF1A5622C669EA40056B3AA /* OSNewRecordsState.swift */,
3C11518A289ADEEB00565C41 /* OSEventProducer.swift */,
Expand Down Expand Up @@ -3750,12 +3783,14 @@
DE7D17F527026BA3002D3A5D /* Sources */,
DE7D17F627026BA3002D3A5D /* Frameworks */,
DE7D17F727026BA3002D3A5D /* Resources */,
3C5C6FEC2FC902A100102E2C /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
DE7D181B27026BEC002D3A5D /* PBXTargetDependency */,
DE7D18D52703ADE0002D3A5D /* PBXTargetDependency */,
3C5C6FEB2FC902A100102E2C /* PBXTargetDependency */,
);
name = OneSignalExtension;
productName = OneSignalExtension;
Expand Down Expand Up @@ -3888,6 +3923,7 @@
DEF784452912E16F00A1F3A5 /* PBXTargetDependency */,
DE2D8F482947D85800844084 /* PBXTargetDependency */,
DE2D8F4D2947D86200844084 /* PBXTargetDependency */,
3C5C6FF32FC903B900102E2C /* PBXTargetDependency */,
);
name = OneSignalNotifications;
productName = OneSignalNotifications;
Expand Down Expand Up @@ -4349,6 +4385,7 @@
3C11518B289ADEEB00565C41 /* OSEventProducer.swift in Sources */,
3C115165289A259500565C41 /* OneSignalOSCore.docc in Sources */,
5BC1DE5E2C90B80E00CA8807 /* OSCondition.swift in Sources */,
3C5C6FE72FC9008A00102E2C /* OSResilientStorage.swift in Sources */,
5BC1DE5C2C90B7E600CA8807 /* OSConsistencyManager.swift in Sources */,
3C115189289ADEA300565C41 /* OSModelStore.swift in Sources */,
3C115185289ADE4F00565C41 /* OSModel.swift in Sources */,
Expand Down Expand Up @@ -4795,6 +4832,16 @@
target = 3C115160289A259500565C41 /* OneSignalOSCore */;
targetProxy = 3C115199289AF86C00565C41 /* PBXContainerItemProxy */;
};
3C5C6FEB2FC902A100102E2C /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 3C115160289A259500565C41 /* OneSignalOSCore */;
targetProxy = 3C5C6FEA2FC902A100102E2C /* PBXContainerItemProxy */;
};
3C5C6FF32FC903B900102E2C /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 3C115160289A259500565C41 /* OneSignalOSCore */;
targetProxy = 3C5C6FF22FC903B900102E2C /* PBXContainerItemProxy */;
};
3C60BB9E2ECF860600C765F7 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = DEBAAE272A4211D900BF2C1C /* OneSignalInAppMessages */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

#import <OneSignalCore/OneSignalCore.h>
#import <OneSignalOSCore/OneSignalOSCore-Swift.h>
#import "OSMacros.h"
#import <OneSignalOutcomes/OneSignalOutcomes.h>
#import "OneSignalNotificationServiceExtensionHandler.h"
Expand Down Expand Up @@ -141,8 +142,19 @@ + (void)onNotificationReceived:(NSString *)receivedNotificationId withBlockingTa

// Track confirmed delivery
let sharedUserDefaults = OneSignalUserDefaults.initShared;
let playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil];
let appId = [sharedUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil];
NSString *playerId = [sharedUserDefaults getSavedStringForKey:OSUD_PUSH_SUBSCRIPTION_ID defaultValue:nil];
NSString *appId = [sharedUserDefaults getSavedStringForKey:OSUD_APP_ID defaultValue:nil];

// Fall back to the unencrypted cache if UserDefaults reads return nil.
// This handles cases where the NSE runs while the device is locked and the
// UserDefaults file (NSFileProtectionCompleteUntilFirstUserAuthentication) is not readable.
if (!playerId) {
playerId = [OSResilientStorage stringForKey:OSResilientStorage.keySubscriptionId];
}
if (!appId) {
appId = [OSResilientStorage stringForKey:OSResilientStorage.keyAppId];
}

// Randomize send of confirmed deliveries to lessen traffic for high recipient notifications
int randomDelay = semaphore != nil ? arc4random_uniform(MAX_CONF_DELIVERY_DELAY) : 0;
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"OneSignal onNotificationReceived sendReceiveReceipt with delay: %i", randomDelay]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@
#import <Foundation/Foundation.h>
#import "OneSignalReceiveReceiptsController.h"
#import <OneSignalCore/OneSignalCore.h>
#import <OneSignalOSCore/OneSignalOSCore-Swift.h>
#import "OSMacros.h"
#import "OneSignalExtensionRequests.h"

@implementation OneSignalReceiveReceiptsController

- (BOOL)isReceiveReceiptsEnabled {
return [OneSignalUserDefaults.initShared getSavedBoolForKey:OSUD_RECEIVE_RECEIPTS_ENABLED defaultValue:NO];
BOOL enabled = [OneSignalUserDefaults.initShared getSavedBoolForKey:OSUD_RECEIVE_RECEIPTS_ENABLED defaultValue:NO];
if (enabled) {
return YES;
}
// UserDefaults may return NO for two reasons: the flag is genuinely off, or the shared
// UserDefaults file isn't readable right now (NSE running while device is locked under
// NSFileProtectionCompleteUntilFirstUserAuthentication). Fall back to the unencrypted cache.
NSString *cached = [OSResilientStorage stringForKey:OSResilientStorage.keyReceiveReceiptsEnabled];
return [cached isEqualToString:@"1"];
}

- (void)sendReceiveReceiptWithNotificationId:(NSString *)notificationId {
Expand Down
160 changes: 160 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSResilientStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
Modified MIT License

Copyright 2026 OneSignal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

2. All copies of substantial portions of the Software may only be used in connection
with services provided by OneSignal.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import Foundation
import OneSignalCore

/// File-backed mirror of OneSignal SDK identifiers, written with `NSFileProtectionNone`
/// so it's readable before first unlock, when shared `UserDefaults` reads silently return nil.
///
/// Stored in the App Group container, so it's shared across any targets (main app, NSE, etc.)
/// configured with the same App Group entitlement. Opaque identifiers only: no PII or credentials.
@objc(OSResilientStorage)
public final class OSResilientStorage: NSObject {

// MARK: - Public key constants

@objc public static let keyAppId = "app_id"
@objc public static let keySubscriptionId = "subscription_id"
@objc public static let keyOneSignalId = "onesignal_id"
/// Needed because the NSE reads this flag from shared UserDefaults while the device may be locked
/// and the read silently returns the default (NO). Stored as "1" / "0".
@objc public static let keyReceiveReceiptsEnabled = "receive_receipts_enabled"

// MARK: - Internal

private static let fileName = "onesignal_identity.json"

/// Serial queue used to serialize all file reads/writes.
private static let queue = DispatchQueue(label: "com.onesignal.resilient-storage")

/// Resolve a writable container URL. App Group container is preferred so
/// the NSE can read the same file. Falls back to the app's private
/// Application Support directory when no App Group is entitled.
private static func fileURL() -> URL? {
let fm = FileManager.default

let groupName = OneSignalUserDefaults.appGroupName()
if let container = fm.containerURL(forSecurityApplicationGroupIdentifier: groupName) {
return container.appendingPathComponent(fileName)
}

do {
let support = try fm.url(
for: .applicationSupportDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true
)
return support.appendingPathComponent(fileName)
} catch {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSResilientStorage could not resolve a container URL: \(error)")
return nil
}
}

/// Reads the cache file. Caller is responsible for queue-serialization.
/// Returns an empty dict if the file is missing or unreadable.
private static func loadUnsafe() -> [String: String] {
guard let url = fileURL() else { return [:] }
guard FileManager.default.fileExists(atPath: url.path) else { return [:] }

do {
let data = try Data(contentsOf: url)
if data.isEmpty { return [:] }
let object = try JSONSerialization.jsonObject(with: data, options: [])
return (object as? [String: String]) ?? [:]
} catch {
OneSignalLog.onesignalLog(.LL_WARN, message: "OSResilientStorage could not read file: \(error)")
return [:]
}
}

/// Writes the cache file atomically with `.none` file protection.
/// Caller is responsible for queue-serialization.
private static func writeUnsafe(_ contents: [String: String]) {
guard let url = fileURL() else { return }

do {
let data = try JSONSerialization.data(withJSONObject: contents, options: [])
try data.write(to: url, options: [.atomic, .noFileProtection])

// Explicitly re-apply protection class. The atomic write performs a rename which
// has been observed to reset attributes on some iOS versions.
try FileManager.default.setAttributes(
[.protectionKey: FileProtectionType.none],
ofItemAtPath: url.path
)
} catch {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OSResilientStorage write failed: \(error)")
}
}

// MARK: - Public API

/// Returns the full current contents of the cache. Empty dict if absent.
@objc public static func snapshot() -> [String: String] {
return queue.sync { loadUnsafe() }
}

/// Reads a single value. Returns nil when missing or unreadable.
@objc public static func string(forKey key: String) -> String? {
let dict = snapshot()
guard let value = dict[key], !value.isEmpty else { return nil }
return value
}

/// Atomically updates a single value. Passing nil or an empty string removes the key.
@objc public static func setString(_ value: String?, forKey key: String) {
queue.async {
var current = loadUnsafe()
if let value = value, !value.isEmpty {
current[key] = value
} else {
current.removeValue(forKey: key)
}
writeUnsafe(current)
}
}

/// Atomically updates multiple values, preserving keys not in `values`.
/// An empty-string value removes the corresponding key.
@objc public static func setStrings(_ values: [String: String]) {
guard !values.isEmpty else { return }
queue.async {
var current = loadUnsafe()
for (key, value) in values {
if value.isEmpty {
current.removeValue(forKey: key)
} else {
current[key] = value
}
}
writeUnsafe(current)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class OSIdentityModel: OSModel {
OneSignalUserDefaults.initShared().saveString(forKey: OS_SNAPSHOT_ONESIGNAL_ID, withValue: newOnesignalId)
OneSignalUserDefaults.initShared().saveString(forKey: OS_SNAPSHOT_EXTERNAL_ID, withValue: newExternalId)

// Mirror onesignal_id to the unencrypted cache; external_id is intentionally NOT cached as it can be PII.
OSResilientStorage.setString(newOnesignalId ?? "", forKey: OSResilientStorage.keyOneSignalId)

let curUserState = OSUserState(onesignalId: newOnesignalId, externalId: newExternalId)
let changedState = OSUserChangedState(current: curUserState)

Expand Down
Loading
Loading