Skip to content

Commit cb30103

Browse files
authored
fixing deprecation warnings (#427)
* fixing deprecation warnings * remove comment
1 parent af1abd5 commit cb30103

File tree

12 files changed

+154
-49
lines changed

12 files changed

+154
-49
lines changed

Leanplum-SDK/Classes/Features/Inbox/LPInbox.m

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,27 @@ - (void)load
281281
NSMutableDictionary *messages;
282282
if (encryptedData) {
283283
NSData *decryptedData = [LPAES decryptedDataFromData:encryptedData];
284-
if (!decryptedData) {
284+
if (!decryptedData || decryptedData.length == 0) {
285285
return;
286286
}
287287

288-
NSKeyedUnarchiver *archiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:decryptedData];
289-
messages = (NSMutableDictionary *)[archiver decodeObjectForKey:LP_PARAM_INBOX_MESSAGES];
288+
NSKeyedUnarchiver *unarchiver;
289+
if (@available(iOS 12.0, *)) {
290+
NSError *error = nil;
291+
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:decryptedData error:&error];
292+
if (error != nil) {
293+
LPLog(LPError, error.localizedDescription);
294+
return;;
295+
}
296+
unarchiver.requiresSecureCoding = NO;
297+
} else {
298+
#pragma clang diagnostic push
299+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
300+
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:decryptedData];
301+
#pragma clang diagnostic pop
302+
}
303+
304+
messages = (NSMutableDictionary *)[unarchiver decodeObjectForKey:LP_PARAM_INBOX_MESSAGES];
290305
if (!messages) {
291306
messages = [NSMutableDictionary dictionary];
292307
}
@@ -327,7 +342,17 @@ - (void)save
327342
{
328343
RETURN_IF_NOOP;
329344
NSMutableData *data = [[NSMutableData alloc] init];
330-
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
345+
346+
NSKeyedArchiver *archiver;
347+
if (@available(iOS 12.0, *)) {
348+
archiver = [[NSKeyedArchiver alloc] initRequiringSecureCoding:NO];
349+
} else {
350+
#pragma clang diagnostic push
351+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
352+
archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
353+
#pragma clang diagnostic pop
354+
}
355+
331356
[archiver encodeObject:[self messages] forKey:LP_PARAM_INBOX_MESSAGES];
332357
[archiver finishEncoding];
333358

Leanplum-SDK/Classes/Features/Variables/LPVarCache.m

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,29 @@ - (void)loadDiffs
398398
return;
399399
}
400400

401-
NSKeyedUnarchiver *archiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:diffsData];
402-
diffs = (NSDictionary *) [archiver decodeObjectForKey:LEANPLUM_DEFAULTS_VARIABLES_KEY];
403-
messages = (NSDictionary *) [archiver decodeObjectForKey:LEANPLUM_DEFAULTS_MESSAGES_KEY];
404-
regions = (NSDictionary *)[archiver decodeObjectForKey:LP_KEY_REGIONS];
405-
variants = (NSArray *)[archiver decodeObjectForKey:LP_KEY_VARIANTS];
406-
variantDebugInfo = (NSDictionary *)[archiver decodeObjectForKey:LP_KEY_VARIANT_DEBUG_INFO];
407-
NSString *deviceId = [archiver decodeObjectForKey:LP_PARAM_DEVICE_ID];
408-
NSString *userId = [archiver decodeObjectForKey:LP_PARAM_USER_ID];
409-
BOOL loggingEnabled = [archiver decodeBoolForKey:LP_KEY_LOGGING_ENABLED];
401+
NSKeyedUnarchiver *unarchiver;
402+
if (@available(iOS 12.0, *)) {
403+
NSError *error = nil;
404+
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:diffsData error:&error];
405+
if (error != nil) {
406+
LPLog(LPError, error.localizedDescription);
407+
return;
408+
}
409+
unarchiver.requiresSecureCoding = NO;
410+
} else {
411+
#pragma clang diagnostic push
412+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
413+
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:diffsData];
414+
#pragma clang diagnostic pop
415+
}
416+
diffs = (NSDictionary *) [unarchiver decodeObjectForKey:LEANPLUM_DEFAULTS_VARIABLES_KEY];
417+
messages = (NSDictionary *) [unarchiver decodeObjectForKey:LEANPLUM_DEFAULTS_MESSAGES_KEY];
418+
regions = (NSDictionary *)[unarchiver decodeObjectForKey:LP_KEY_REGIONS];
419+
variants = (NSArray *)[unarchiver decodeObjectForKey:LP_KEY_VARIANTS];
420+
variantDebugInfo = (NSDictionary *)[unarchiver decodeObjectForKey:LP_KEY_VARIANT_DEBUG_INFO];
421+
NSString *deviceId = [unarchiver decodeObjectForKey:LP_PARAM_DEVICE_ID];
422+
NSString *userId = [unarchiver decodeObjectForKey:LP_PARAM_USER_ID];
423+
BOOL loggingEnabled = [unarchiver decodeBoolForKey:LP_KEY_LOGGING_ENABLED];
410424

411425
if (deviceId) {
412426
[[LPAPIConfig sharedConfig] setDeviceId:deviceId];
@@ -441,7 +455,10 @@ - (void)saveDiffs
441455
// mergeHelper:.
442456
@synchronized (self.diffs) {
443457
NSMutableData *diffsData = [[NSMutableData alloc] init];
458+
#pragma clang diagnostic push
459+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
444460
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:diffsData];
461+
#pragma clang diagnostic pop
445462
[archiver encodeObject:self.diffs forKey:LEANPLUM_DEFAULTS_VARIABLES_KEY];
446463
[archiver encodeObject:self.messages forKey:LEANPLUM_DEFAULTS_MESSAGES_KEY];
447464
[archiver encodeObject:self.variants forKey:LP_KEY_VARIANTS];
@@ -703,9 +720,24 @@ - (NSMutableDictionary *)userAttributes
703720
if (encryptedValue) {
704721
NSData *decryptedData = [LPAES decryptedDataFromData:encryptedValue];
705722
if (decryptedData) {
706-
NSKeyedUnarchiver *archiver = [[NSKeyedUnarchiver alloc] initForReadingWithData
723+
NSKeyedUnarchiver *unarchiver;
724+
if (@available(iOS 12.0, *)) {
725+
NSError *error = nil;
726+
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:decryptedData error:&error];
727+
if (error != nil) {
728+
LPLog(LPError, error.localizedDescription);
729+
//in case of error returning empty dictionary to avoid crash
730+
return [NSMutableDictionary dictionary];
731+
}
732+
unarchiver.requiresSecureCoding = NO;
733+
} else {
734+
#pragma clang diagnostic push
735+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
736+
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData
707737
:decryptedData];
708-
self.userAttributes = [(NSDictionary *)[archiver decodeObjectForKey:LP_PARAM_USER_ATTRIBUTES] mutableCopy];
738+
#pragma clang diagnostic pop
739+
}
740+
self.userAttributes = [(NSDictionary *)[unarchiver decodeObjectForKey:LP_PARAM_USER_ATTRIBUTES] mutableCopy];
709741
}
710742
}
711743
}
@@ -723,7 +755,10 @@ - (void)saveUserAttributes
723755
{
724756
RETURN_IF_NOOP;
725757
NSMutableData *data = [[NSMutableData alloc] init];
758+
#pragma clang diagnostic push
759+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
726760
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
761+
#pragma clang diagnostic pop
727762
[archiver encodeObject:self.userAttributes forKey:LP_PARAM_USER_ATTRIBUTES];
728763
[archiver finishEncoding];
729764

Leanplum-SDK/Classes/Internal/Leanplum.m

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,12 +1087,15 @@ + (void)startWithUserId:(NSString *)userId
10871087
usingBlock:^(NSNotification *notification) {
10881088
RETURN_IF_NOOP;
10891089
LP_TRY
1090+
#pragma clang diagnostic push
1091+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
10901092
if ([[UIApplication sharedApplication]
10911093
respondsToSelector:@selector(currentUserNotificationSettings)]) {
10921094
[[LPPushNotificationsManager sharedManager].handler sendUserNotificationSettingsIfChanged:
10931095
[[UIApplication sharedApplication]
10941096
currentUserNotificationSettings]];
10951097
}
1098+
#pragma clang diagnostic pop
10961099
[Leanplum resume];
10971100
[self maybePerformActions:@[@"resume"]
10981101
withEventName:nil
@@ -1622,20 +1625,6 @@ + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
16221625
LP_END_TRY
16231626
}
16241627

1625-
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
1626-
{
1627-
LP_TRY
1628-
if (![LPUtils isSwizzlingEnabled])
1629-
{
1630-
[[LPPushNotificationsManager sharedManager].handler didRegisterUserNotificationSettings:notificationSettings];
1631-
}
1632-
else
1633-
{
1634-
LPLog(LPDebug, @"Call to didRegisterUserNotificationSettings will be ignored due to swizzling.");
1635-
}
1636-
LP_END_TRY
1637-
}
1638-
16391628
+ (void)didReceiveRemoteNotification:(NSDictionary *)userInfo
16401629
{
16411630
LP_TRY
@@ -1682,6 +1671,23 @@ + (void)didReceiveNotificationResponse:(UNNotificationResponse *)response
16821671
LP_END_TRY
16831672
}
16841673

1674+
#pragma clang diagnostic push
1675+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
1676+
#pragma clang diagnostic ignored "-Wstrict-prototypes"
1677+
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
1678+
{
1679+
LP_TRY
1680+
if (![LPUtils isSwizzlingEnabled])
1681+
{
1682+
[[LPPushNotificationsManager sharedManager].handler didRegisterUserNotificationSettings:notificationSettings];
1683+
}
1684+
else
1685+
{
1686+
LPLog(LPDebug, @"Call to didRegisterUserNotificationSettings will be ignored due to swizzling.");
1687+
}
1688+
LP_END_TRY
1689+
}
1690+
16851691
+ (void)didReceiveLocalNotification:(UILocalNotification *)localNotification
16861692
{
16871693
LP_TRY
@@ -1696,8 +1702,6 @@ + (void)didReceiveLocalNotification:(UILocalNotification *)localNotification
16961702
LP_END_TRY
16971703
}
16981704

1699-
#pragma clang diagnostic push
1700-
#pragma clang diagnostic ignored "-Wstrict-prototypes"
17011705
+ (void)handleActionWithIdentifier:(NSString *)identifier
17021706
forLocalNotification:(UILocalNotification *)notification
17031707
completionHandler:(void (^)(LeanplumUIBackgroundFetchResult))completionHandler

Leanplum-SDK/Classes/MessageTemplates/LPOpenUrlMessageTemplate.m

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,7 @@ - (void) openURL
3636
dispatch_async(dispatch_get_main_queue(), ^{
3737
NSString *encodedURLString = [self urlEncodedStringFromString:[self.context stringNamed:LPMT_ARG_URL]];
3838
NSURL *url = [NSURL URLWithString: encodedURLString];
39-
if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
40-
if (@available(iOS 10.0, *)) {
41-
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
42-
} else {
43-
// Fallback on earlier versions
44-
}
45-
} else {
46-
[[UIApplication sharedApplication] openURL:url];
47-
}
39+
[LPUtils openURL:url];
4840
});
4941

5042
}

Leanplum-SDK/Classes/MessageTemplates/ViewControllers/LPWebInterstitialViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
243243
if ([app canOpenURL:navigationUrl])
244244
{
245245
[self.webView stopLoading];
246-
[app openURL:[NSURL URLWithString:url]];
246+
[LPUtils openURL:[NSURL URLWithString:url]];
247247
decisionHandler(WKNavigationActionPolicyCancel);
248248
return;
249249
} else{

Leanplum-SDK/Classes/Notifications/Local/LPLocalNotificationsHandler.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#import "LPNotificationsManager.h"
1212

1313
@implementation LPLocalNotificationsHandler
14-
14+
#pragma clang diagnostic push
15+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
1516
- (void)didReceiveLocalNotification:(UILocalNotification *)localNotification
1617
{
1718
NSDictionary *userInfo = [localNotification userInfo];
@@ -20,5 +21,6 @@ - (void)didReceiveLocalNotification:(UILocalNotification *)localNotification
2021
[[LPNotificationsManager shared] handleLocalNotification:userInfo];
2122
LP_END_TRY
2223
}
24+
#pragma clang diagnostic pop
2325

2426
@end

Leanplum-SDK/Classes/Notifications/Local/LPLocalNotificationsManager.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ - (void)listenForLocalNotifications
138138
}];
139139

140140
} else {
141+
// Fallback on earlier versions
142+
#pragma clang diagnostic push
143+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
141144
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
142145
localNotif.fireDate = eta;
143146
localNotif.timeZone = [NSTimeZone defaultTimeZone];
@@ -168,6 +171,7 @@ - (void)listenForLocalNotifications
168171

169172
// Schedule the notification
170173
[app scheduleLocalNotification:localNotif];
174+
#pragma clang diagnostic pop
171175
}
172176

173177
if ([LPConstantsState sharedState].isDevelopmentModeEnabled) {
@@ -176,7 +180,8 @@ - (void)listenForLocalNotifications
176180
LP_BEGIN_USER_CODE
177181
return YES;
178182
}];
179-
183+
#pragma clang diagnostic push
184+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
180185
[Leanplum onAction:@"__Cancel__Push Notification" invoke:^BOOL(LPActionContext *context) {
181186
LP_END_USER_CODE
182187
UIApplication *app = [UIApplication sharedApplication];
@@ -218,8 +223,11 @@ - (void)listenForLocalNotifications
218223
return didCancel;
219224
}
220225
}];
226+
#pragma clang diagnostic pop
221227
}
222228

229+
#pragma clang diagnostic push
230+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
223231
- (BOOL)shouldSendNotificationForMessage:(NSString *)message contentAvailable:(BOOL)contentAvailable
224232
{
225233
// Don't send notification if the user doesn't have the permission enabled.
@@ -278,5 +286,6 @@ - (BOOL)shouldDiscard:(NSDate *)eta context:(LPActionContext *)context
278286
return NO;
279287
}
280288
}
289+
#pragma clang diagnostic pop
281290

282291
@end

Leanplum-SDK/Classes/Notifications/Push/LPPushNotificationsHandler.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ @interface LPPushNotificationsHandler()
1919
@property (nonatomic, strong) NSDate *notificationHandledTime;
2020
@end
2121

22+
#pragma clang diagnostic push
23+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
24+
#pragma clang diagnostic ignored "-Wstrict-prototypes"
2225
@interface UIUserNotificationSettings (LPUtil)
2326
@property (readonly, nonatomic) NSDictionary *dictionary;
2427
@end
@@ -210,6 +213,7 @@ - (void)leanplum_disableAskToAsk
210213
[[LPMessageTemplatesClass sharedTemplates] disableAskToAsk];
211214
}
212215
}
216+
#pragma clang diagnostic pop
213217

214218
#pragma mark - Push Notifications - Handlers
215219

Leanplum-SDK/Classes/Notifications/Push/LPPushNotificationsManager.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ - (void)leanplum_application:(UIApplication *)application didRegisterForRemoteNo
2525
}
2626
}
2727

28+
#pragma clang diagnostic push
29+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
30+
#pragma clang diagnostic ignored "-Wstrict-prototypes"
2831
- (void)leanplum_application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
2932
{
3033
LPLog(LPDebug, @"Called swizzled didRegisterUserNotificationSettings:notificationSettings");
@@ -98,8 +101,6 @@ - (void)leanplum_application:(UIApplication *)application
98101
state.calledHandleNotification = NO;
99102
}
100103

101-
#pragma clang diagnostic push
102-
#pragma clang diagnostic ignored "-Wstrict-prototypes"
103104
- (void)leanplum_userNotificationCenter:(UNUserNotificationCenter *)center
104105
didReceiveNotificationResponse:(UNNotificationResponse *)response
105106
withCompletionHandler:(void (^)())completionHandler
@@ -141,8 +142,6 @@ -(void)leanplum_userNotificationCenter:(UNUserNotificationCenter *)center
141142
[[LPPushNotificationsManager sharedManager].handler willPresentNotification:notification withCompletionHandler:completionHandler];
142143
}
143144

144-
#pragma clang diagnostic pop
145-
146145
- (void)leanplum_application:(UIApplication *)application
147146
didReceiveLocalNotification:(UILocalNotification *)localNotification
148147
{
@@ -157,6 +156,7 @@ - (void)leanplum_application:(UIApplication *)application
157156
}
158157
}
159158

159+
#pragma clang diagnostic pop
160160

161161
@end
162162

@@ -234,11 +234,13 @@ -(void)enableSystemPush
234234
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
235235
if (@available(iOS 8.0, *))
236236
{
237+
#pragma clang diagnostic push
238+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
237239
UIUserNotificationType notificationTypes = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
238240
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
239241
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
240242
[[UIApplication sharedApplication] registerForRemoteNotifications];
241-
243+
#pragma clang diagnostic pop
242244
return;
243245
}
244246
#endif

Leanplum-SDK/Classes/Utilities/LPDatabase.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,19 @@ - (NSArray *)rowsFromQuery:(NSString *)query bindObjects:(NSArray *)objectsToBin
226226
if (sqlite3_column_type(statement, i) == SQLITE_BLOB) {
227227
NSData *columnBytes = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement, i)
228228
length:sqlite3_column_bytes(statement, i)];
229-
columnData[columnKey] = [NSKeyedUnarchiver unarchiveObjectWithData:columnBytes];
229+
if (@available(iOS 12.0, *)) {
230+
NSError *error = nil;
231+
columnData[columnKey] = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSString class] fromData:columnBytes error:&error];
232+
if (error != nil) {
233+
LPLog(LPError, error.localizedDescription);
234+
return nil;
235+
}
236+
} else {
237+
#pragma clang diagnostic push
238+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
239+
columnData[columnKey] = [NSKeyedUnarchiver unarchiveObjectWithData:columnBytes];
240+
#pragma clang diagnostic pop
241+
}
230242
} else {
231243
char *columnValueUTF8 = (char *)sqlite3_column_text(statement, i);
232244
if (columnValueUTF8) {

0 commit comments

Comments
 (0)