Skip to content
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
36 changes: 36 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
3C14E3B32FAE54C006ED053 /* OSLoggerPlatformProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C14E3AC2FAE54C006ED053 /* OSLoggerPlatformProvider.swift */; };
3C14E3B42FAE54C006ED053 /* KotlinByteArray+Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C14E3AD2FAE54C006ED053 /* KotlinByteArray+Data.swift */; };
3C14E3B52FAE54C006ED053 /* OSLoggerAdaptersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C14E3AE2FAE54C006ED053 /* OSLoggerAdaptersTests.swift */; };
A5048F01A1B2C3D4E5F60002 /* OSFeatureFlagsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5048F01A1B2C3D4E5F60001 /* OSFeatureFlagsStore.swift */; };
A5048F01A1B2C3D4E5F60004 /* OSFeatureFlagsBackendService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5048F01A1B2C3D4E5F60003 /* OSFeatureFlagsBackendService.swift */; };
A5048F01A1B2C3D4E5F60006 /* OSFeatureManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5048F01A1B2C3D4E5F60005 /* OSFeatureManager.swift */; };
A5048F01A1B2C3D4E5F6000D /* OSFeatureManagerImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5048F01A1B2C3D4E5F6000C /* OSFeatureManagerImpl.swift */; };
A5048F01A1B2C3D4E5F60008 /* OSFeatureFlagsRefreshService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5048F01A1B2C3D4E5F60007 /* OSFeatureFlagsRefreshService.swift */; };
A5048F01A1B2C3D4E5F6000A /* OSFeatureFlagsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5048F01A1B2C3D4E5F60009 /* OSFeatureFlagsTests.swift */; };
A5048F01A1B2C3D4E5F6100B /* OSFeatureFlagsRefreshServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5048F01A1B2C3D4E5F6100A /* OSFeatureFlagsRefreshServiceTests.swift */; };
C781A33FED62B4B54221A09A /* OSLogCrashHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B6A59620B83538CEFF77269 /* OSLogCrashHandlerTests.swift */; };
B96A3B6BA8CC49EE4796D9BF /* OSRemoteLoggingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A72F938F8A3808AC1FF7F3C /* OSRemoteLoggingController.swift */; };
25898119922BDCDA7AF0B9CC /* OSRemoteLoggingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A72F938F8A3808AC1FF7F3C /* OSRemoteLoggingController.swift */; };
Expand Down Expand Up @@ -1798,6 +1805,13 @@
3C14E3AC2FAE54C006ED053 /* OSLoggerPlatformProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLoggerPlatformProvider.swift; sourceTree = "<group>"; };
3C14E3AD2FAE54C006ED053 /* KotlinByteArray+Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KotlinByteArray+Data.swift"; sourceTree = "<group>"; };
3C14E3AE2FAE54C006ED053 /* OSLoggerAdaptersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLoggerAdaptersTests.swift; sourceTree = "<group>"; };
A5048F01A1B2C3D4E5F60001 /* OSFeatureFlagsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSFeatureFlagsStore.swift; sourceTree = "<group>"; };
A5048F01A1B2C3D4E5F60003 /* OSFeatureFlagsBackendService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSFeatureFlagsBackendService.swift; sourceTree = "<group>"; };
A5048F01A1B2C3D4E5F60005 /* OSFeatureManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSFeatureManager.swift; sourceTree = "<group>"; };
A5048F01A1B2C3D4E5F6000C /* OSFeatureManagerImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSFeatureManagerImpl.swift; sourceTree = "<group>"; };
A5048F01A1B2C3D4E5F60007 /* OSFeatureFlagsRefreshService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSFeatureFlagsRefreshService.swift; sourceTree = "<group>"; };
A5048F01A1B2C3D4E5F60009 /* OSFeatureFlagsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSFeatureFlagsTests.swift; sourceTree = "<group>"; };
A5048F01A1B2C3D4E5F6100A /* OSFeatureFlagsRefreshServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSFeatureFlagsRefreshServiceTests.swift; sourceTree = "<group>"; };
3B6A59620B83538CEFF77269 /* OSLogCrashHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLogCrashHandlerTests.swift; sourceTree = "<group>"; };
8A72F938F8A3808AC1FF7F3C /* OSRemoteLoggingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSRemoteLoggingController.swift; sourceTree = "<group>"; };
C0462F96E1AADF655F3B3765 /* OSRemoteLoggingController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSRemoteLoggingController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2269,6 +2283,7 @@
isa = PBXGroup;
children = (
5BC1DE652C90BC9F00CA8807 /* Consistency */,
A5048F01A1B2C3D4E5F6000B /* Feature */,
3C14E3AF2FAE54C006ED053 /* Logging */,
3C115163289A259500565C41 /* OneSignalOSCore.h */,
3C115188289ADEA300565C41 /* OSModelStore.swift */,
Expand Down Expand Up @@ -2306,6 +2321,18 @@
path = Logging;
sourceTree = "<group>";
};
A5048F01A1B2C3D4E5F6000B /* Feature */ = {
isa = PBXGroup;
children = (
A5048F01A1B2C3D4E5F60003 /* OSFeatureFlagsBackendService.swift */,
A5048F01A1B2C3D4E5F60007 /* OSFeatureFlagsRefreshService.swift */,
A5048F01A1B2C3D4E5F60001 /* OSFeatureFlagsStore.swift */,
A5048F01A1B2C3D4E5F60005 /* OSFeatureManager.swift */,
A5048F01A1B2C3D4E5F6000C /* OSFeatureManagerImpl.swift */,
);
path = Feature;
sourceTree = "<group>";
};
3C70222A2ECF126B001768C6 /* OneSignalInAppMessagesMocks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2574,6 +2601,8 @@
5BC1DE672C90C23E00CA8807 /* OSConsistencyManagerTests.swift */,
3C427AC8301BB28A0059B8B7 /* OSOperationRepoFlushTests.swift */,
3C14E3AE2FAE54C006ED053 /* OSLoggerAdaptersTests.swift */,
A5048F01A1B2C3D4E5F60009 /* OSFeatureFlagsTests.swift */,
A5048F01A1B2C3D4E5F6100A /* OSFeatureFlagsRefreshServiceTests.swift */,
3B6A59620B83538CEFF77269 /* OSLogCrashHandlerTests.swift */,
3C23A21A2FCE0A52001D32E3 /* OneSignalIdentifiersFallbackTests.swift */,
3C23A21E2FCE0AA1001D32E3 /* OSResilientStorageTests.swift */,
Expand Down Expand Up @@ -4446,6 +4475,11 @@
3C14E3B22FAE54C006ED053 /* FileLogStore.swift in Sources */,
5BC1DE602C90B83900CA8807 /* OSConsistencyKeyEnum.swift in Sources */,
3C14E3B12FAE54C006ED053 /* OneSignalLogHttpSender.swift in Sources */,
A5048F01A1B2C3D4E5F60002 /* OSFeatureFlagsStore.swift in Sources */,
A5048F01A1B2C3D4E5F60004 /* OSFeatureFlagsBackendService.swift in Sources */,
A5048F01A1B2C3D4E5F60006 /* OSFeatureManager.swift in Sources */,
A5048F01A1B2C3D4E5F6000D /* OSFeatureManagerImpl.swift in Sources */,
A5048F01A1B2C3D4E5F60008 /* OSFeatureFlagsRefreshService.swift in Sources */,
3C4F9E4428A4466C009F453A /* OSOperationRepo.swift in Sources */,
3C14E3B02FAE54C006ED053 /* IOSLogger.swift in Sources */,
698F58A488FCE503DFD5247F /* OSLogCrashHandler.swift in Sources */,
Expand Down Expand Up @@ -4611,6 +4645,8 @@
3C23A21D2FCE0A83001D32E3 /* OSModelStoreRefreshTests.swift in Sources */,
3C427AC9301BB28A0059B8B7 /* OSOperationRepoFlushTests.swift in Sources */,
3C14E3B52FAE54C006ED053 /* OSLoggerAdaptersTests.swift in Sources */,
A5048F01A1B2C3D4E5F6000A /* OSFeatureFlagsTests.swift in Sources */,
A5048F01A1B2C3D4E5F6100B /* OSFeatureFlagsRefreshServiceTests.swift in Sources */,
C781A33FED62B4B54221A09A /* OSLogCrashHandlerTests.swift in Sources */,
3C23A21B2FCE0A52001D32E3 /* OneSignalIdentifiersFallbackTests.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5B053FB72CAE07EB002F30C4"
BuildableName = "OneSignalOSCoreTests.xctest"
BlueprintName = "OneSignalOSCoreTests"
ReferencedContainer = "container:OneSignal.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
// Remote Params
#define OSUD_LOCATION_ENABLED @"OSUD_LOCATION_ENABLED"
#define OSUD_REQUIRES_USER_PRIVACY_CONSENT @"OSUD_REQUIRES_USER_PRIVACY_CONSENT"
// Remote SDK feature flags (Turbine GET apps/{app_id}/sdk/features/{platform}/{sdk_version})
#define OSUD_SDK_REMOTE_FEATURE_FLAGS @"OSUD_SDK_REMOTE_FEATURE_FLAGS"
#define OSUD_SDK_REMOTE_FEATURE_FLAG_METADATA @"OSUD_SDK_REMOTE_FEATURE_FLAG_METADATA"
// Remote Params - Receive Receipts
#define OSUD_RECEIVE_RECEIPTS_ENABLED @"OS_ENABLE_RECEIVE_RECEIPTS" // * OSUD_RECEIVE_RECEIPTS_ENABLED
// Outcomes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
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
@_implementationOnly import OneSignalKMP

/// iOS host for the shared Turbine feature-flags client.
///
/// This class is the platform adapter matching Android `FeatureFlagsBackendService`:
/// wrap native HTTP as `IFeatureFlagsHttp`, construct `FeatureFlagsClient`, log
/// unavailable outcomes at the right severity, and leave path/parse/orchestration in KMP.
final class OSFeatureFlagsBackendService {
static let turbineFeaturesPlatformIOS = "ios"

typealias FetchCompletion = (RemoteFeatureFlagsFetchOutcome) -> Void

private let client: FeatureFlagsClient
private let sdkVersionProvider: () -> String

init(
http: IFeatureFlagsHttp,
sdkVersionProvider: @escaping () -> String = { ONESIGNAL_VERSION }
) {
self.client = FeatureFlagsClient(http: http)
self.sdkVersionProvider = sdkVersionProvider
}

convenience init(
requestSender: @escaping OSFeatureFlagsHttpAdapter.RequestSender = OSFeatureFlagsHttpAdapter.defaultSender
) {
self.init(http: OSFeatureFlagsHttpAdapter(requestSender: requestSender))
}

func fetchRemoteFeatureFlags(appId: String, completion: @escaping FetchCompletion) {
OneSignalLog.onesignalLog(
.LL_DEBUG,
message: "FeatureFlagsBackendService.fetchRemoteFeatureFlags(appId=\(appId))"
)
let sdkVersion = sdkVersionProvider()
client.fetchRemoteFeatureFlags(appId: appId, platform: Self.turbineFeaturesPlatformIOS, sdkVersion: sdkVersion) {
outcome,
error in
let resolved: RemoteFeatureFlagsFetchOutcome
if let outcome {
resolved = outcome
} else {
resolved = RemoteFeatureFlagsFetchOutcome.companion.unavailable(
reason: .nonSuccessHttp,
statusCode: KotlinInt(int: 0),
bodySnippet: error?.localizedDescription ?? "<empty>"
)
}
if resolved.isUnavailable {
Self.logUnavailable(resolved, appId: appId, sdkVersion: sdkVersion)
}
completion(resolved)
}
}

private static func logUnavailable(
_ outcome: RemoteFeatureFlagsFetchOutcome,
appId: String,
sdkVersion: String
) {
let reason = outcome.reason
if reason == RemoteFeatureFlagsUnavailableReason.invalidAppId {
OneSignalLog.onesignalLog(
.LL_WARN,
message: "FeatureFlagsBackendService: app id not usable for Turbine path: '\(appId)'"
)
} else if reason == RemoteFeatureFlagsUnavailableReason.invalidSdkVersion {
OneSignalLog.onesignalLog(
.LL_WARN,
message: "FeatureFlagsBackendService: sdk version not usable for Turbine path (expected "
+ "6-digit label optional -suffix, e.g. 050801 or 050801-beta): '\(sdkVersion)'"
)
} else if reason == RemoteFeatureFlagsUnavailableReason.nonSuccessHttp {
let message =
"FeatureFlagsBackendService: non-success status=\(statusDescription(outcome.statusCode)) "
+ "body=\(outcome.bodySnippet ?? "<empty>")"
if outcome.isClientError {
OneSignalLog.onesignalLog(.LL_WARN, message: message)
} else {
OneSignalLog.onesignalLog(.LL_DEBUG, message: message)
}
} else if reason == RemoteFeatureFlagsUnavailableReason.emptyBody {
OneSignalLog.onesignalLog(
.LL_WARN,
message: "FeatureFlagsBackendService: empty body for success status=\(statusDescription(outcome.statusCode))"
)
} else if reason == RemoteFeatureFlagsUnavailableReason.invalidJson {
OneSignalLog.onesignalLog(
.LL_WARN,
message: "FeatureFlagsBackendService: response body is not valid Turbine feature-flags JSON: "
+ (outcome.bodySnippet ?? "<empty>")
)
} else {
OneSignalLog.onesignalLog(
.LL_WARN,
message: "FeatureFlagsBackendService: unavailable without reason"
)
}
}

private static func statusDescription(_ statusCode: KotlinInt?) -> String {
statusCode.map { "\($0.intValue)" } ?? "nil"
}
}

/// URLSession (or injected sender) as `IFeatureFlagsHttp`. Resolves KMP's relative path
/// against `OS_API_SERVER_URL` and attaches the same SDK-Version / Accept headers as
/// `OneSignalRequest`.
final class OSFeatureFlagsHttpAdapter: IFeatureFlagsHttp {
typealias RequestSender = (
URLRequest,
@escaping (Data?, URLResponse?, Error?) -> Void
) -> Void

private static let requestTimeout: TimeInterval = 10

static let defaultSender: RequestSender = { request, completion in
defaultSession.dataTask(with: request, completionHandler: completion).resume()
}

private static let defaultSession: URLSession = {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = requestTimeout
configuration.timeoutIntervalForResource = requestTimeout
configuration.requestCachePolicy = .reloadIgnoringLocalCacheData
return URLSession(configuration: configuration)
}()

private let requestSender: RequestSender

init(requestSender: @escaping RequestSender = OSFeatureFlagsHttpAdapter.defaultSender) {
self.requestSender = requestSender
}

func get(relativePath: String, completionHandler: @escaping (FeatureFlagsHttpResponse?, Error?) -> Void) {
// `OneSignalRequest` is used for the base URL and the standard SDK headers only.
// Its `disableLocalCaching` flag is read by `OneSignalClient`, which this path
// deliberately bypasses, so cache policy is set on the session instead.
let request = OneSignalRequest()
request.method = GET
request.path = relativePath
requestSender(request.urlRequest() as URLRequest) { data, response, error in
let statusCode: Int32
if error != nil {
statusCode = 0
} else if let http = response as? HTTPURLResponse {
statusCode = Int32(http.statusCode)
} else {
statusCode = 0
}
// A transport failure carries no HTTP status, so forward the error text as the
// body. Without it every such failure logs as `status=0 body=<empty>` and
// offline, DNS, TLS, and timeout are indistinguishable in the field.
let body: String?
if let error {
body = error.localizedDescription
} else {
body = data.flatMap { String(data: $0, encoding: .utf8) }
}
completionHandler(FeatureFlagsHttpResponse(statusCode: statusCode, body: body), nil)
}
}
}
Loading
Loading