Skip to content

Commit ae9f468

Browse files
committed
Maintain semantic and numeric version of SDK
* Keep a semantic and numeric representation of the SDK version, this will be updated by our release script. * Create OneSignalVersion to manage and provide the two representations. Swift cannot use C preprocessor macros.
1 parent 7a22b21 commit ae9f468

10 files changed

Lines changed: 117 additions & 10 deletions

File tree

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152
3CC063E62B6D7F96002BB07F /* OneSignalUserMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CC063E52B6D7F96002BB07F /* OneSignalUserMocks.swift */; };
153153
3CC063EE2B6D7FE8002BB07F /* OneSignalUserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CC063ED2B6D7FE8002BB07F /* OneSignalUserTests.swift */; };
154154
3CC063EF2B6D7FE8002BB07F /* OneSignalUser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DE69E19B282ED8060090BB3D /* OneSignalUser.framework */; };
155+
3CC47E072EB2D31400C4E4DB /* OneSignalVersion.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CC47E052EB2D31400C4E4DB /* OneSignalVersion.h */; settings = {ATTRIBUTES = (Public, ); }; };
156+
3CC47E082EB2D31400C4E4DB /* OneSignalVersion.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CC47E062EB2D31400C4E4DB /* OneSignalVersion.m */; };
155157
3CC890352C5BF9A7002CB4CC /* UserConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CC890342C5BF9A7002CB4CC /* UserConcurrencyTests.swift */; };
156158
3CC9A6342AFA1FDE008F68FD /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3CC9A6332AFA1FDD008F68FD /* PrivacyInfo.xcprivacy */; };
157159
3CC9A6362AFA26E7008F68FD /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3CC9A6352AFA26E7008F68FD /* PrivacyInfo.xcprivacy */; };
@@ -1315,6 +1317,8 @@
13151317
3CC063E52B6D7F96002BB07F /* OneSignalUserMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneSignalUserMocks.swift; sourceTree = "<group>"; };
13161318
3CC063EB2B6D7FE8002BB07F /* OneSignalUserTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OneSignalUserTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
13171319
3CC063ED2B6D7FE8002BB07F /* OneSignalUserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneSignalUserTests.swift; sourceTree = "<group>"; };
1320+
3CC47E052EB2D31400C4E4DB /* OneSignalVersion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalVersion.h; sourceTree = "<group>"; };
1321+
3CC47E062EB2D31400C4E4DB /* OneSignalVersion.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalVersion.m; sourceTree = "<group>"; };
13181322
3CC890342C5BF9A7002CB4CC /* UserConcurrencyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserConcurrencyTests.swift; sourceTree = "<group>"; };
13191323
3CC9A6332AFA1FDD008F68FD /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
13201324
3CC9A6352AFA26E7008F68FD /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
@@ -2652,6 +2656,8 @@
26522656
DEBA2A252C20E9AA00E234DB /* OSBundleUtils.m */,
26532657
3C55013E2E09CF0100E77DF7 /* OSCopyOnWriteSet.h */,
26542658
3C55013F2E09CF0100E77DF7 /* OSCopyOnWriteSet.m */,
2659+
3CC47E052EB2D31400C4E4DB /* OneSignalVersion.h */,
2660+
3CC47E062EB2D31400C4E4DB /* OneSignalVersion.m */,
26552661
);
26562662
path = Source;
26572663
sourceTree = "<group>";
@@ -3173,6 +3179,7 @@
31733179
DE7D183D27027F13002D3A5D /* NSURL+OneSignal.h in Headers */,
31743180
DEBA2A282C24D0F400E234DB /* OSBundleUtils.h in Headers */,
31753181
DEF784792914667A00A1F3A5 /* NSDateFormatter+OneSignal.h in Headers */,
3182+
3CC47E072EB2D31400C4E4DB /* OneSignalVersion.h in Headers */,
31763183
DE7D17EB27026B95002D3A5D /* OneSignalCore.h in Headers */,
31773184
DE7D182A270271A9002D3A5D /* OneSignalCommonDefines.h in Headers */,
31783185
3CE8CC522911AE90000DB0D3 /* OSNetworkingUtils.h in Headers */,
@@ -4462,6 +4469,7 @@
44624469
3CCF44BF299B17290021964D /* OneSignalWrapper.m in Sources */,
44634470
DEF78492291479B200A1F3A5 /* OneSignalSelectorHelpers.m in Sources */,
44644471
DE7D182B27027376002D3A5D /* OSNotification.m in Sources */,
4472+
3CC47E082EB2D31400C4E4DB /* OneSignalVersion.m in Sources */,
44654473
DE7D187A27037A26002D3A5D /* OneSignalCoreHelper.m in Sources */,
44664474
3CE8CC4F2911ADD1000DB0D3 /* OSDeviceUtils.m in Sources */,
44674475
DE7D1864270374EE002D3A5D /* OneSignalClient.m in Sources */,

iOS_SDK/OneSignalSDK/OneSignalCore/Source/API/OneSignalRequest.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import "OneSignalCommonDefines.h"
3030
#import "OneSignalLog.h"
3131
#import "OneSignalWrapper.h"
32+
#import "OneSignalVersion.h"
3233

3334
#define HTTP_HEADER_KEY_OS_VERSION @"SDK-Version"
3435
#define HTTP_HEADER_KEY_OS_WRAPPER @"SDK-Wrapper"
@@ -70,8 +71,8 @@ -(NSMutableURLRequest *)urlRequest {
7071
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
7172

7273
[request setValue:OS_API_ACCEPT_HEADER forHTTPHeaderField:@"Accept"];
73-
74-
NSString *versionString = [NSString stringWithFormat:@"%@%@", HTTP_HEADER_PREFIX_OS_VERSION, ONESIGNAL_VERSION];
74+
75+
NSString *versionString = [NSString stringWithFormat:@"%@%@", HTTP_HEADER_PREFIX_OS_VERSION, OneSignalVersion.numeric];
7576
[request setValue:versionString forHTTPHeaderField:HTTP_HEADER_KEY_OS_VERSION];
7677

7778
// Set header field if this is used in a wrapper SDK

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCommonDefines.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
// "*" in comment line ending comment means the string value has not been changed
4747
// App
4848

49-
#define ONESIGNAL_VERSION @"050215"
50-
5149
#define OSUD_APP_ID @"GT_APP_ID" // * OSUD_APP_ID
5250
#define OSUD_REGISTERED_WITH_APPLE @"GT_REGISTERED_WITH_APPLE" // * OSUD_REGISTERED_WITH_APPLE
5351
#define OSUD_APP_PROVIDES_NOTIFICATION_SETTINGS @"OS_APP_PROVIDES_NOTIFICATION_SETTINGS" // * OSUD_APP_PROVIDES_NOTIFICATION_SETTINGS

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#import <OneSignalCore/OSBundleUtils.h>
6060
#import <OneSignalCore/OneSignalClientError.h>
6161
#import <OneSignalCore/OneSignalBadgeHelpers.h>
62+
#import <OneSignalCore/OneSignalVersion.h>
6263

6364
// TODO: Testing: Should this class be defined in this file?
6465
@interface OneSignalCoreImpl : NSObject

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OneSignalCore.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ + (void)migrateCachedSdkVersion {
5555
}
5656

5757
+ (void)saveCurrentSDKVersion {
58-
int currentVersion = [ONESIGNAL_VERSION intValue];
58+
int currentVersion = [OneSignalVersion.numeric intValue];
5959
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_CORE withValue:currentVersion];
6060
}
6161

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2025 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import <Foundation/Foundation.h>
29+
30+
NS_ASSUME_NONNULL_BEGIN
31+
32+
/**
33+
* Provides access to OneSignal SDK version information.
34+
* Exposes version strings in different formats for use in both Objective-C and Swift.
35+
*/
36+
@interface OneSignalVersion : NSObject
37+
38+
/**
39+
* Returns the semantic version string (e.g., "5.2.15" or "5.2.3-beta-01")
40+
*/
41+
+ (NSString *)semantic;
42+
43+
/**
44+
* Returns the numeric version string with zero-padded components (e.g., "050215" or "050203-beta-01")
45+
* Each numeric component is padded to 2 digits. Pre-release suffixes are preserved.
46+
*/
47+
+ (NSString *)numeric;
48+
49+
@end
50+
51+
NS_ASSUME_NONNULL_END
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2025 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import "OneSignalVersion.h"
29+
30+
/**
31+
* The SDK version - these values are updated by the automation when releasing
32+
* SEMANTIC: "5.2.15" or "5.2.3-beta-01"
33+
* NUMERIC: "050215" or "050203-beta-01" (zero-padded with optional suffix)
34+
*/
35+
static NSString * const ONESIGNAL_VERSION_SEMANTIC = @"5.2.15";
36+
static NSString * const ONESIGNAL_VERSION_NUMERIC = @"050215";
37+
38+
@implementation OneSignalVersion
39+
40+
+ (NSString *)semantic {
41+
return ONESIGNAL_VERSION_SEMANTIC;
42+
}
43+
44+
+ (NSString *)numeric {
45+
return ONESIGNAL_VERSION_NUMERIC;
46+
}
47+
48+
@end

iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSInAppMessageMigrationController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ + (void)migrateToOSInAppMessageInternal {
9090
}
9191

9292
+ (void)saveCurrentSDKVersion {
93-
int currentVersion = [ONESIGNAL_VERSION intValue];
93+
int currentVersion = [OneSignalVersion.numeric intValue];
9494
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_IAM withValue:currentVersion];
9595
}
9696

iOS_SDK/OneSignalSDK/OneSignalOutcomes/OSOutcomes.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ + (void)migrateToVersion_02_14_00_AndGreater {
8484
}
8585
}
8686
+ (void)saveCurrentSDKVersion {
87-
let currentVersion = [ONESIGNAL_VERSION intValue];
87+
let currentVersion = [OneSignalVersion.numeric intValue];
8888
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION_FOR_OUTCOMES withValue:currentVersion];
8989
}
9090

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class OSSubscriptionModel: OSModel {
219219
}
220220
}
221221

222-
var sdk = ONESIGNAL_VERSION {
222+
var sdk = OneSignalVersion.numeric() {
223223
didSet {
224224
guard sdk != oldValue else {
225225
return
@@ -324,7 +324,7 @@ class OSSubscriptionModel: OSModel {
324324
self.notificationTypes = coder.decodeInteger(forKey: "notificationTypes")
325325
self.testType = coder.decodeObject(forKey: "testType") as? Int
326326
self.deviceOs = coder.decodeObject(forKey: "deviceOs") as? String ?? UIDevice.current.systemVersion
327-
self.sdk = coder.decodeObject(forKey: "sdk") as? String ?? ONESIGNAL_VERSION
327+
self.sdk = coder.decodeObject(forKey: "sdk") as? String ?? OneSignalVersion.numeric()
328328
self.deviceModel = coder.decodeObject(forKey: "deviceModel") as? String
329329
self.appVersion = coder.decodeObject(forKey: "appVersion") as? String
330330
self.netType = coder.decodeObject(forKey: "netType") as? Int
@@ -425,7 +425,7 @@ extension OSSubscriptionModel {
425425
func update() {
426426
updateTestType()
427427
deviceOs = UIDevice.current.systemVersion
428-
sdk = ONESIGNAL_VERSION
428+
sdk = OneSignalVersion.numeric()
429429
deviceModel = OSDeviceUtils.getDeviceVariant()
430430
appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
431431
netType = OSNetworkingUtils.getNetType() as? Int

0 commit comments

Comments
 (0)