|
| 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 |
0 commit comments