Skip to content

Commit c773202

Browse files
committed
adding outcomes migration to OneSignalOutcomes
This is called from the NSE
1 parent 8c57492 commit c773202

File tree

9 files changed

+87
-13
lines changed

9 files changed

+87
-13
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5151

5252
NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);
5353

54-
[OneSignalLog setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
54+
[OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
5555
_notificationDelegate = [OneSignalNotificationCenterDelegate new];
5656

5757
id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
@@ -70,7 +70,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
7070
// Example block for IAM action click handler
7171
id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) {
7272
NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]];
73-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message];
73+
[OneSignal onesignalLog:ONE_S_LL_DEBUG message:message];
7474
};
7575

7676
// Example setter for IAM action click handler using OneSignal public method

iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5151

5252
NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);
5353

54-
[OneSignalLog setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
54+
[OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
5555
_notificationDelegate = [OneSignalNotificationCenterDelegate new];
5656

5757
id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
@@ -65,7 +65,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
6565
// Example block for IAM action click handler
6666
id inAppMessagingActionClickBlock = ^(OSInAppMessageAction *action) {
6767
NSString *message = [NSString stringWithFormat:@"Click Action Occurred: %@", [action jsonRepresentation]];
68-
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:message];
68+
[OneSignal onesignalLog:ONE_S_LL_DEBUG message:message];
6969
};
7070

7171
// Example setter for IAM action click handler using OneSignal public method

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@
386386
DE3CD2FA270F9A6D00A5BECD /* OSNotification+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE3CD2F8270F9A6D00A5BECD /* OSNotification+OneSignal.m */; };
387387
DE3CD2FB270F9A6D00A5BECD /* OSNotification+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE3CD2F8270F9A6D00A5BECD /* OSNotification+OneSignal.m */; };
388388
DE3CD2FD270F9A8100A5BECD /* OSNotification+OneSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = DE3CD2FC270F9A8100A5BECD /* OSNotification+OneSignal.h */; };
389+
DE3CD2FF270FA9F200A5BECD /* OneSignalOutcomes.m in Sources */ = {isa = PBXBuildFile; fileRef = DE3CD2FE270FA9F200A5BECD /* OneSignalOutcomes.m */; };
390+
DE3CD300270FA9F200A5BECD /* OneSignalOutcomes.m in Sources */ = {isa = PBXBuildFile; fileRef = DE3CD2FE270FA9F200A5BECD /* OneSignalOutcomes.m */; };
389391
DE5EFECA24D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */; };
390392
DE7D17EA27026B95002D3A5D /* OneSignalCore.docc in Sources */ = {isa = PBXBuildFile; fileRef = DE7D17E927026B95002D3A5D /* OneSignalCore.docc */; };
391393
DE7D17EB27026B95002D3A5D /* OneSignalCore.h in Headers */ = {isa = PBXBuildFile; fileRef = DE7D17E827026B95002D3A5D /* OneSignalCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -937,6 +939,7 @@
937939
DE367CC624EEF2BE00165207 /* OSInAppMessagePage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessagePage.m; sourceTree = "<group>"; };
938940
DE3CD2F8270F9A6D00A5BECD /* OSNotification+OneSignal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OSNotification+OneSignal.m"; sourceTree = "<group>"; };
939941
DE3CD2FC270F9A8100A5BECD /* OSNotification+OneSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OSNotification+OneSignal.h"; sourceTree = "<group>"; };
942+
DE3CD2FE270FA9F200A5BECD /* OneSignalOutcomes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalOutcomes.m; sourceTree = "<group>"; };
940943
DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageViewControllerOverrider.m; sourceTree = "<group>"; };
941944
DE5EFECB24D8DC0E0032632D /* OSInAppMessageViewControllerOverrider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageViewControllerOverrider.h; sourceTree = "<group>"; };
942945
DE7D17E627026B95002D3A5D /* OneSignalCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OneSignalCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1577,6 +1580,7 @@
15771580
children = (
15781581
DE7D188D27037F5C002D3A5D /* Source */,
15791582
DE7D188227037F43002D3A5D /* OneSignalOutcomes.h */,
1583+
DE3CD2FE270FA9F200A5BECD /* OneSignalOutcomes.m */,
15801584
7A880F2923FB45CE0081F5E8 /* OSInAppMessageOutcome.h */,
15811585
7A880F2A23FB45FB0081F5E8 /* OSInAppMessageOutcome.m */,
15821586
DE7D188327037F43002D3A5D /* OneSignalOutcomes.docc */,
@@ -2518,6 +2522,7 @@
25182522
A63E9E3B26742B4700EA273E /* LanguageProviderDevice.m in Sources */,
25192523
9129C6BA1E89E59B009CB6A0 /* OSPermission.m in Sources */,
25202524
91F58D871E7C88250017D24D /* OneSignalNotificationSettingsIOS9.m in Sources */,
2525+
DE3CD2FF270FA9F200A5BECD /* OneSignalOutcomes.m in Sources */,
25212526
CA1A6E7220DC2E73001C41B9 /* OneSignalDialogRequest.m in Sources */,
25222527
7A880F332404AE7B0081F5E8 /* OSInAppMessagePushPrompt.m in Sources */,
25232528
);
@@ -2580,6 +2585,7 @@
25802585
DE7D18A027038125002D3A5D /* OSInAppMessageTracker.m in Sources */,
25812586
DE7D18BA27038185002D3A5D /* OSOutcomeSourceBody.m in Sources */,
25822587
DE7D18A22703812D002D3A5D /* OSNotificationTracker.m in Sources */,
2588+
DE3CD300270FA9F200A5BECD /* OneSignalOutcomes.m in Sources */,
25832589
DE7D18B82703817D002D3A5D /* OSCachedUniqueOutcome.m in Sources */,
25842590
DE7D18BE27038194002D3A5D /* OSOutcomeEventParams.m in Sources */,
25852591
DE7D18C02703819D002D3A5D /* OSOutcomeEventsV1Repository.m in Sources */,

iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalNotificationServiceExtensionHandler.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ + (void)addActionButtonsToExtentionRequest:(UNNotificationRequest*)request
133133

134134
+ (void)onNotificationReceived:(NSString *)receivedNotificationId withBlockingTask:(dispatch_semaphore_t)semaphore {
135135
if (receivedNotificationId && ![receivedNotificationId isEqualToString:@""]) {
136-
// ECM TODO: We probably need to rearchitect migrations a bit. Each module needs to migrate the models it is responsible for
137136
// If update was made without app being initialized/launched before -> migrate
138-
// [[OSMigrationController new] migrate];
137+
[OneSignalOutcomes migrate];
139138
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"NSE request received, sessionManager: %@", [OSSessionManager sharedSessionManager]]];
140139
// Save received notification id
141140
[[OSSessionManager sharedSessionManager] onNotificationReceived:receivedNotificationId];

iOS_SDK/OneSignalSDK/OneSignalOutcomes/OneSignalOutcomes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
#import "OSOutcomeEvent.h"
3535
#import "OSInfluenceDataDefines.h"
3636
#import "OSOutcomeEventsCache.h"
37+
#import "OSCachedUniqueOutcome.h"
3738

39+
@interface OneSignalOutcomes : NSObject
40+
+ (void)migrate;
41+
@end
3842

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Modified MIT License
3+
4+
Copyright 2021 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+
#import "OneSignalOutcomes.h"
28+
#import <OneSignalCore/OneSignalCore.h>
29+
30+
@implementation OneSignalOutcomes
31+
32+
+ (void)migrate {
33+
[self migrateToVersion_02_14_00_AndGreater];
34+
[self saveCurrentSDKVersion];
35+
}
36+
37+
/**
38+
* Support renaming of decodable classes for cached data
39+
*/
40+
+ (void)migrateToVersion_02_14_00_AndGreater {
41+
let influenceVersion = 21400;
42+
let uniqueCacheOutcomeVersion = 21403;
43+
long sdkVersion = [OneSignalUserDefaults.initShared getSavedIntegerForKey:OSUD_CACHED_SDK_VERSION defaultValue:0];
44+
if (sdkVersion < influenceVersion) {
45+
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSIndirectNotification from version: %ld", sdkVersion]];
46+
47+
[NSKeyedUnarchiver setClass:[OSIndirectInfluence class] forClassName:@"OSIndirectNotification"];
48+
NSArray<OSIndirectInfluence *> * indirectInfluenceData = [[OSInfluenceDataRepository sharedInfluenceDataRepository] lastNotificationsReceivedData];
49+
if (indirectInfluenceData) {
50+
[NSKeyedArchiver setClassName:@"OSIndirectInfluence" forClass:[OSIndirectInfluence class]];
51+
[[OSInfluenceDataRepository sharedInfluenceDataRepository] saveNotifications:indirectInfluenceData];
52+
}
53+
}
54+
55+
if (sdkVersion < uniqueCacheOutcomeVersion) {
56+
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG message:[NSString stringWithFormat:@"Migrating OSUniqueOutcomeNotification from version: %ld", sdkVersion]];
57+
58+
[NSKeyedUnarchiver setClass:[OSCachedUniqueOutcome class] forClassName:@"OSUniqueOutcomeNotification"];
59+
NSArray<OSCachedUniqueOutcome *> * attributedCacheUniqueOutcomeEvents = [[OSOutcomeEventsCache sharedOutcomeEventsCache] getAttributedUniqueOutcomeEventSent];
60+
if (attributedCacheUniqueOutcomeEvents) {
61+
[NSKeyedArchiver setClassName:@"OSCachedUniqueOutcome" forClass:[OSCachedUniqueOutcome class]];
62+
[[OSOutcomeEventsCache sharedOutcomeEventsCache] saveAttributedUniqueOutcomeEventNotificationIds:attributedCacheUniqueOutcomeEvents];
63+
}
64+
}
65+
}
66+
+ (void)saveCurrentSDKVersion {
67+
let currentVersion = [ONESIGNAL_VERSION intValue];
68+
[OneSignalUserDefaults.initShared saveIntegerForKey:OSUD_CACHED_SDK_VERSION withValue:currentVersion];
69+
}
70+
@end

iOS_SDK/OneSignalSDK/Source/OSMigrationController.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
2828
#import <Foundation/Foundation.h>
2929
#import "OSMigrationController.h"
3030
#import <OneSignalOutcomes/OneSignalOutcomes.h>
31-
#import "OSOutcomeEventsCache.h"
32-
#import "OSIndirectInfluence.h"
33-
#import "OSCachedUniqueOutcome.h"
3431
#import "OneSignal.h"
35-
#import "OneSignalUserDefaults.h"
36-
#import "OneSignalCommonDefines.h"
3732
#import "OSInAppMessagingDefines.h"
3833
#import "OneSignalHelper.h"
3934
#import "OSInAppMessageInternal.h"

iOS_SDK/OneSignalSDK/UnitTests/SMSTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ - (void)setUp {
8686
self.ONESIGNAL_EXTERNAL_USER_ID = @"test_external_user_id";
8787
self.ONESIGNAL_EXTERNAL_USER_ID_HASH_TOKEN = @"test_external_user_id_hash_token";
8888

89-
[OneSignalLog setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
89+
[OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
9090
}
9191

9292
/*

iOS_SDK/OneSignalSDK/UnitTests/UnitTestCommonMethods.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ + (void)clearStateForAppRestart:(XCTestCase *)testCase {
225225

226226
[UIAlertViewOverrider reset];
227227

228-
[OneSignalLog setLogLevel:ONE_S_LL_INFO visualLevel:ONE_S_LL_NONE];
228+
[OneSignal setLogLevel:ONE_S_LL_INFO visualLevel:ONE_S_LL_NONE];
229229

230230
[NSTimerOverrider reset];
231231
[OneSignalLocationOverrider reset];

0 commit comments

Comments
 (0)