From 9582f5c48fa476147e0fc4cfcb41893c8c336a65 Mon Sep 17 00:00:00 2001 From: Guy Kogus Date: Wed, 12 Jul 2023 16:47:13 +0200 Subject: [PATCH] Upgrade to minimum iOS version 10.0 --- Leanplum-iOS-Location.podspec | 4 +- Leanplum-iOS-LocationAndBeacons.podspec | 4 +- Leanplum-iOS-SDK.podspec | 2 +- .../LeanplumSDK.xcodeproj/project.pbxproj | 24 +-- .../LeanplumSDK/Classes/Internal/Leanplum.m | 41 ---- LeanplumSDK/LeanplumSDK/Classes/Leanplum.h | 35 +--- .../Local/LPLocalNotificationsManager.m | 184 ++++++------------ .../LeanplumSDK/Classes/Utilities/LPUtils.m | 12 +- ...UIUserNotificationSettings+Transform.swift | 30 --- .../UNNotificationSettings+Transform.swift | 1 - .../NSObject+Notifications.swift | 46 +---- .../Notifications/NotificationSettings.swift | 41 ++-- .../NotificationsManager+Utilities.swift | 30 ++- .../Notifications/NotificationsManager.swift | 7 - .../Proxy/NotificationsProxy+Disabled.swift | 18 +- .../Proxy/NotificationsProxy+Swizzling.swift | 1 - .../Proxy/NotificationsProxy+iOS9.swift | 39 ---- .../Proxy/NotificationsProxy.swift | 49 ++--- .../LeanplumSDKApp.xcodeproj/project.pbxproj | 6 +- .../PushNotificationSettingsTest.swift | 4 - .../project.pbxproj | 12 +- Podfile | 2 +- 22 files changed, 117 insertions(+), 475 deletions(-) delete mode 100644 LeanplumSDK/LeanplumSDK/ClassesSwift/Extensions/UIUserNotificationSettings+Transform.swift delete mode 100644 LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+iOS9.swift diff --git a/Leanplum-iOS-Location.podspec b/Leanplum-iOS-Location.podspec index a2338ce5..fae3ee71 100644 --- a/Leanplum-iOS-Location.podspec +++ b/Leanplum-iOS-Location.podspec @@ -8,13 +8,13 @@ Pod::Spec.new do |s| s.license = { :type => 'Commercial', :text => 'See https://www.leanplum.com/tos' } s.author = { 'Leanplum' => 'support@leanplum.com' } s.social_media_url = 'https://twitter.com/leanplum' - s.platform = :ios, '9.0' + s.platform = :ios, '10.0' s.requires_arc = true s.source = { :git => 'https://github.com/Leanplum/Leanplum-iOS-SDK.git', :tag => s.version.to_s} s.source_files = 'LeanplumSDKLocation/LeanplumSDKLocation/Classes/**/*' s.frameworks = 'CoreLocation' s.documentation_url = 'https://docs.leanplum.com/' - s.dependency 'Leanplum-iOS-SDK', "~> 6.0" + s.dependency 'Leanplum-iOS-SDK', "~> 7.0" s.module_name = 'LeanplumLocation' s.swift_versions = '5.0' end diff --git a/Leanplum-iOS-LocationAndBeacons.podspec b/Leanplum-iOS-LocationAndBeacons.podspec index 0a6514c9..ab96107c 100644 --- a/Leanplum-iOS-LocationAndBeacons.podspec +++ b/Leanplum-iOS-LocationAndBeacons.podspec @@ -8,13 +8,13 @@ Pod::Spec.new do |s| s.license = { :type => 'Commercial', :text => 'See https://www.leanplum.com/tos' } s.author = { 'Leanplum' => 'support@leanplum.com' } s.social_media_url = 'https://twitter.com/leanplum' - s.platform = :ios, '9.0' + s.platform = :ios, '10.0' s.requires_arc = true s.source = { :git => 'https://github.com/Leanplum/Leanplum-iOS-SDK.git', :tag => s.version.to_s} s.source_files = 'LeanplumSDKLocation/LeanplumSDKLocation/Classes/**/*' s.frameworks = 'CoreLocation' s.documentation_url = 'https://docs.leanplum.com/' - s.dependency 'Leanplum-iOS-SDK', "~> 6.0" + s.dependency 'Leanplum-iOS-SDK', "~> 7.0" s.module_name = 'LeanplumLocationAndBeacons' s.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => 'LP_BEACON=1' } s.swift_versions = '5.0' diff --git a/Leanplum-iOS-SDK.podspec b/Leanplum-iOS-SDK.podspec index 7760d3b7..eed027b0 100644 --- a/Leanplum-iOS-SDK.podspec +++ b/Leanplum-iOS-SDK.podspec @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.social_media_url = 'https://twitter.com/leanplum' s.requires_arc = true s.source = { :git => 'https://github.com/Leanplum/Leanplum-iOS-SDK.git', :tag => s.version.to_s } - s.ios.deployment_target = '9.0' + s.ios.deployment_target = '10.0' s.frameworks = 'CFNetwork', 'Foundation', 'Security', 'SystemConfiguration', 'UIKit' s.weak_frameworks = 'AdSupport', 'StoreKit' s.library = 'sqlite3' diff --git a/LeanplumSDK/LeanplumSDK.xcodeproj/project.pbxproj b/LeanplumSDK/LeanplumSDK.xcodeproj/project.pbxproj index 32215147..59f7cda0 100644 --- a/LeanplumSDK/LeanplumSDK.xcodeproj/project.pbxproj +++ b/LeanplumSDK/LeanplumSDK.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -482,8 +482,6 @@ 6AD9784F2774EDF600A7C6C6 /* NotificationsProxy+Disabled.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD9784D2774EDF600A7C6C6 /* NotificationsProxy+Disabled.swift */; }; 6AD978512774F08300A7C6C6 /* NotificationsProxy+Swizzling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD978502774F08300A7C6C6 /* NotificationsProxy+Swizzling.swift */; }; 6AD978522774F08300A7C6C6 /* NotificationsProxy+Swizzling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD978502774F08300A7C6C6 /* NotificationsProxy+Swizzling.swift */; }; - 6AD978542774F2F700A7C6C6 /* NotificationsProxy+iOS9.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD978532774F2F700A7C6C6 /* NotificationsProxy+iOS9.swift */; }; - 6AD978552774F2F700A7C6C6 /* NotificationsProxy+iOS9.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD978532774F2F700A7C6C6 /* NotificationsProxy+iOS9.swift */; }; 6AD978572774F3F000A7C6C6 /* NotificationsProxy+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD978562774F3F000A7C6C6 /* NotificationsProxy+Utilities.swift */; }; 6AD978582774F3F000A7C6C6 /* NotificationsProxy+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD978562774F3F000A7C6C6 /* NotificationsProxy+Utilities.swift */; }; 6ADC90C72807461F00CE42C7 /* Dictionary+ValueKeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ADC90C62807461F00CE42C7 /* Dictionary+ValueKeyPath.swift */; }; @@ -491,8 +489,6 @@ A0371C8C3E1D6D0AB924FF99 /* libPods-Leanplum-Static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 897B64EE76852A68ECECB184 /* libPods-Leanplum-Static.a */; }; C90C489D2707299D00E33F1F /* NotificationSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90C489C2707299D00E33F1F /* NotificationSettings.swift */; }; C90C489E2707299D00E33F1F /* NotificationSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90C489C2707299D00E33F1F /* NotificationSettings.swift */; }; - C90C48A027072A0200E33F1F /* UIUserNotificationSettings+Transform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90C489F27072A0200E33F1F /* UIUserNotificationSettings+Transform.swift */; }; - C90C48A127072A0200E33F1F /* UIUserNotificationSettings+Transform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90C489F27072A0200E33F1F /* UIUserNotificationSettings+Transform.swift */; }; C90C48A327072A5200E33F1F /* Data+EncodedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90C48A227072A5200E33F1F /* Data+EncodedString.swift */; }; C90C48A427072A5200E33F1F /* Data+EncodedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90C48A227072A5200E33F1F /* Data+EncodedString.swift */; }; C90C48A627072AD800E33F1F /* UNNotificationSettings+Transform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90C48A527072AD800E33F1F /* UNNotificationSettings+Transform.swift */; }; @@ -826,7 +822,6 @@ 6AD978482774BE7500A7C6C6 /* Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = ""; }; 6AD9784D2774EDF600A7C6C6 /* NotificationsProxy+Disabled.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationsProxy+Disabled.swift"; sourceTree = ""; }; 6AD978502774F08300A7C6C6 /* NotificationsProxy+Swizzling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationsProxy+Swizzling.swift"; sourceTree = ""; }; - 6AD978532774F2F700A7C6C6 /* NotificationsProxy+iOS9.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationsProxy+iOS9.swift"; sourceTree = ""; }; 6AD978562774F3F000A7C6C6 /* NotificationsProxy+Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NotificationsProxy+Utilities.swift"; sourceTree = ""; }; 6ADC90C62807461F00CE42C7 /* Dictionary+ValueKeyPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+ValueKeyPath.swift"; sourceTree = ""; }; 6C2FB1913D58B5EF901363C9 /* Pods_Leanplum.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Leanplum.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -834,7 +829,6 @@ B335B24E5DF5CE017C0BE58D /* Pods-Leanplum-Static.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Leanplum-Static.release.xcconfig"; path = "Target Support Files/Pods-Leanplum-Static/Pods-Leanplum-Static.release.xcconfig"; sourceTree = ""; }; C73AA976764CAC7D649E137B /* Pods-Leanplum.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Leanplum.debug.xcconfig"; path = "Target Support Files/Pods-Leanplum/Pods-Leanplum.debug.xcconfig"; sourceTree = ""; }; C90C489C2707299D00E33F1F /* NotificationSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSettings.swift; sourceTree = ""; }; - C90C489F27072A0200E33F1F /* UIUserNotificationSettings+Transform.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIUserNotificationSettings+Transform.swift"; sourceTree = ""; }; C90C48A227072A5200E33F1F /* Data+EncodedString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+EncodedString.swift"; sourceTree = ""; }; C90C48A527072AD800E33F1F /* UNNotificationSettings+Transform.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UNNotificationSettings+Transform.swift"; sourceTree = ""; }; C9374A38272C36B200F4915A /* Utilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = ""; }; @@ -1382,7 +1376,6 @@ 6A265E2527187EBB0074354F /* NotificationsProxy.swift */, 6AD9784D2774EDF600A7C6C6 /* NotificationsProxy+Disabled.swift */, 6AD978502774F08300A7C6C6 /* NotificationsProxy+Swizzling.swift */, - 6AD978532774F2F700A7C6C6 /* NotificationsProxy+iOS9.swift */, 6AD978562774F3F000A7C6C6 /* NotificationsProxy+Utilities.swift */, ); path = Proxy; @@ -1416,7 +1409,6 @@ isa = PBXGroup; children = ( C90C48A227072A5200E33F1F /* Data+EncodedString.swift */, - C90C489F27072A0200E33F1F /* UIUserNotificationSettings+Transform.swift */, C90C48A527072AD800E33F1F /* UNNotificationSettings+Transform.swift */, C9D064DB2775DB1100A7A5F9 /* Dictionary+Equatable.swift */, 39D0AA1327760842003C7192 /* Bundle+Extensions.swift */, @@ -1868,7 +1860,6 @@ 075AAE2A26847EC4007CA1BD /* LPRegisterDevice.m in Sources */, 075AAE7C26847EC4007CA1BD /* LPAES.m in Sources */, 6A2109E328BE88D900DBF4A9 /* MigrationManager.swift in Sources */, - C90C48A027072A0200E33F1F /* UIUserNotificationSettings+Transform.swift in Sources */, 075AAE4326847EC4007CA1BD /* LPInterstitialMessageTemplate.m in Sources */, 075AAE2E26847EC4007CA1BD /* LPCountAggregator.m in Sources */, 075AAE5A26847EC4007CA1BD /* LPAppRatingMessageTemplate.m in Sources */, @@ -1914,7 +1905,6 @@ 39C081A12781D3E900C1DBD6 /* ActionManager+Executor.swift in Sources */, 6A07FDA22811911000995BE3 /* ActionManager+FileDownload.swift in Sources */, 075AAE8126847EC4007CA1BD /* LPSwizzle.m in Sources */, - 6AD978542774F2F700A7C6C6 /* NotificationsProxy+iOS9.swift in Sources */, 6A2E4C22292BAB3400385536 /* CleverTapInstanceCallback.m in Sources */, 075AAE6A26847EC4007CA1BD /* LPLocalNotificationsManager.m in Sources */, C9D064DC2775DB1100A7A5F9 /* Dictionary+Equatable.swift in Sources */, @@ -2003,7 +1993,6 @@ 6A714B7526F8B317004A34A9 /* LPContextualValues.m in Sources */, 6A714B7626F8B317004A34A9 /* LPRegisterDevice.m in Sources */, 6A714B7726F8B317004A34A9 /* LPAES.m in Sources */, - C90C48A127072A0200E33F1F /* UIUserNotificationSettings+Transform.swift in Sources */, 6A714B7826F8B317004A34A9 /* LPInterstitialMessageTemplate.m in Sources */, 6A714B7926F8B317004A34A9 /* LPCountAggregator.m in Sources */, 6A714B7A26F8B317004A34A9 /* LPAppRatingMessageTemplate.m in Sources */, @@ -2044,7 +2033,6 @@ 6A714B9026F8B317004A34A9 /* NSString+MD5Addition.m in Sources */, 6A07FDA32811911000995BE3 /* ActionManager+FileDownload.swift in Sources */, 6A714B9126F8B317004A34A9 /* LPSwizzle.m in Sources */, - 6AD978552774F2F700A7C6C6 /* NotificationsProxy+iOS9.swift in Sources */, 6A2E4C23292BAB3400385536 /* CleverTapInstanceCallback.m in Sources */, 6A714B9226F8B317004A34A9 /* LPLocalNotificationsManager.m in Sources */, C9D064DD2775DB1100A7A5F9 /* Dictionary+Equatable.swift in Sources */, @@ -2131,7 +2119,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -2187,7 +2175,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -2212,7 +2200,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "LeanplumSDK/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -2246,7 +2233,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "LeanplumSDK/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -2274,7 +2260,6 @@ ENABLE_BITCODE = NO; INFOPLIST_FILE = "LeanplumSDKBundle/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; MACOSX_DEPLOYMENT_TARGET = 11.3; PRODUCT_BUNDLE_IDENTIFIER = "com.leanplum.LeanplumSDK-Bundle"; PRODUCT_NAME = "Leanplum-iOS-SDK"; @@ -2297,7 +2282,6 @@ ENABLE_BITCODE = NO; INFOPLIST_FILE = "LeanplumSDKBundle/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; MACOSX_DEPLOYMENT_TARGET = 11.3; PRODUCT_BUNDLE_IDENTIFIER = "com.leanplum.LeanplumSDK-Bundle"; PRODUCT_NAME = "Leanplum-iOS-SDK"; @@ -2325,7 +2309,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "LeanplumSDK/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -2359,7 +2342,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "LeanplumSDK/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/LeanplumSDK/LeanplumSDK/Classes/Internal/Leanplum.m b/LeanplumSDK/LeanplumSDK/Classes/Internal/Leanplum.m index 6914a8a6..9835510c 100644 --- a/LeanplumSDK/LeanplumSDK/Classes/Internal/Leanplum.m +++ b/LeanplumSDK/LeanplumSDK/Classes/Internal/Leanplum.m @@ -1557,47 +1557,6 @@ + (void)willPresentNotification:(UNNotification *)notification LP_END_TRY } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#pragma clang diagnostic ignored "-Wstrict-prototypes" -+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings -{ - LP_TRY - if (![LPUtils isSwizzlingEnabled]) - { - [[Leanplum notificationsManager] didRegisterUserNotificationSettings:notificationSettings]; - } - else - { - LPLog(LPDebug, @"Call to didRegisterUserNotificationSettings will be ignored due to swizzling."); - } - LP_END_TRY -} - -+ (void)didReceiveLocalNotification:(UILocalNotification *)localNotification -{ - LP_TRY - if (![LPUtils isSwizzlingEnabled]) - { - [[Leanplum notificationsManager].proxy applicationWithDidReceive:localNotification]; - } - else - { - LPLog(LPDebug, @"Call to didReceiveLocalNotification will be ignored due to swizzling"); - } - LP_END_TRY -} - -+ (void)handleActionWithIdentifier:(NSString *)identifier - forLocalNotification:(UILocalNotification *)notification - completionHandler:(void (^)(UIBackgroundFetchResult))completionHandler -{ - LP_TRY - [[Leanplum notificationsManager].proxy handleActionWithIdentifier:identifier forLocalNotification:notification]; - LP_END_TRY -} -#pragma clang diagnostic pop - #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wstrict-prototypes" + (void)handleActionWithIdentifier:(NSString *)identifier diff --git a/LeanplumSDK/LeanplumSDK/Classes/Leanplum.h b/LeanplumSDK/LeanplumSDK/Classes/Leanplum.h index feeb0538..a8671f43 100644 --- a/LeanplumSDK/LeanplumSDK/Classes/Leanplum.h +++ b/LeanplumSDK/LeanplumSDK/Classes/Leanplum.h @@ -384,11 +384,6 @@ NS_SWIFT_NAME(defineAction(name:kind:args:options:present:dismiss:)); + (void)applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions; + (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token; + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#pragma clang diagnostic ignored "-Wstrict-prototypes" -+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings; -#pragma clang diagnostic pop /** * Call this method from application:didReceiveRemoteNotification:fetchCompletionHandler when Swizzling is Disabled. * Call the completionHandler yourself. @@ -398,40 +393,22 @@ NS_SWIFT_NAME(defineAction(name:kind:args:options:present:dismiss:)); * Call this method from userNotificationCenter:didReceive:withCompletionHandler when Swizzling is Disabled. * Call the completionHandler yourself. */ -+ (void)didReceiveNotificationResponse:(UNNotificationResponse *)response API_AVAILABLE(ios(10.0)); -/** - * Call this method from userNotificationCenter:willPresent:withCompletionHandler when Swizzling is Disabled. - * Call the completionHandler yourself. - */ -+ (void)willPresentNotification:(UNNotification *)notification API_AVAILABLE(ios(10.0)); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#pragma clang diagnostic ignored "-Wstrict-prototypes" -+ (void)didReceiveLocalNotification:(UILocalNotification *)localNotification; -#pragma clang diagnostic pop - ++ (void)didReceiveNotificationResponse:(UNNotificationResponse *)response; /** - * Call this to handle custom actions for local notifications. + * Call this to handle custom actions for remote notifications. * Call the completionHandler yourself. */ #pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wstrict-prototypes" + (void)handleActionWithIdentifier:(NSString *)identifier - forLocalNotification:(UILocalNotification *)notification + forRemoteNotification:(NSDictionary *)notification completionHandler:(void (^)(UIBackgroundFetchResult))completionHandler; #pragma clang diagnostic pop - /** - * Call this to handle custom actions for remote notifications. + * Call this method from userNotificationCenter:willPresent:withCompletionHandler when Swizzling is Disabled. * Call the completionHandler yourself. */ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wstrict-prototypes" -+ (void)handleActionWithIdentifier:(NSString *)identifier - forRemoteNotification:(NSDictionary *)notification - completionHandler:(void (^)(UIBackgroundFetchResult))completionHandler; -#pragma clang diagnostic pop ++ (void)willPresentNotification:(UNNotification *)notification; /** * Block to call that decides whether a notification should be displayed when it is @@ -463,7 +440,7 @@ NS_SWIFT_NAME(defineAction(name:kind:args:options:present:dismiss:)); */ + (void)setPushDeliveryTrackingEnabled:(BOOL)enabled; -+ (void)setPushNotificationPresentationOption:(UNNotificationPresentationOptions)options API_AVAILABLE(ios(10.0)); ++ (void)setPushNotificationPresentationOption:(UNNotificationPresentationOptions)options; /** * @{ diff --git a/LeanplumSDK/LeanplumSDK/Classes/Notifications/Local/LPLocalNotificationsManager.m b/LeanplumSDK/LeanplumSDK/Classes/Notifications/Local/LPLocalNotificationsManager.m index a4ea0dc0..38638ff9 100644 --- a/LeanplumSDK/LeanplumSDK/Classes/Notifications/Local/LPLocalNotificationsManager.m +++ b/LeanplumSDK/LeanplumSDK/Classes/Notifications/Local/LPLocalNotificationsManager.m @@ -38,7 +38,6 @@ - (void)scheduleLocalNotification:(LPActionContext *)context - (BOOL)schedule:(LPActionContext *)context { LP_END_USER_CODE - UIApplication *app = [UIApplication sharedApplication]; BOOL contentAvailable = [context boolNamed:@"iOS options.Preload content"]; NSString *message = [context stringNamed:@"Message"]; @@ -106,79 +105,42 @@ - (BOOL)schedule:(LPActionContext *)context mutableInfo[LP_KEY_PUSH_NO_ACTION] = messageId; } } - - if (@available(iOS 10.0, *)) { - UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; - - if (message) { - content.body = message; - } else { - content.body = LP_VALUE_DEFAULT_PUSH_MESSAGE; - } - - if (category) { - content.categoryIdentifier = category; - } - - if (sound) { - content.sound = [UNNotificationSound soundNamed:sound]; - } else { - content.sound = [UNNotificationSound defaultSound]; - } - if (badge) { - content.badge = [NSNumber numberWithInt:[badge intValue]]; - } + UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; - content.userInfo = mutableInfo; - - NSDateComponents *dateComponenets = [[NSDateComponents alloc] init]; - [dateComponenets setSecond:countdownSeconds]; - UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponenets repeats:NO]; - - UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:messageId content:content trigger:trigger]; - - [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { - if (error) { - LPLog(LPError, error.localizedDescription); - } - }]; + if (message) { + content.body = message; } else { - // Fallback on earlier versions -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - UILocalNotification *localNotif = [[UILocalNotification alloc] init]; - localNotif.fireDate = eta; - localNotif.timeZone = [NSTimeZone defaultTimeZone]; - if (message) { - localNotif.alertBody = message; - } else { - localNotif.alertBody = LP_VALUE_DEFAULT_PUSH_MESSAGE; - } - localNotif.alertAction = @"View"; + content.body = LP_VALUE_DEFAULT_PUSH_MESSAGE; + } - if ([localNotif respondsToSelector:@selector(setCategory:)]) { - if (category) { - localNotif.category = category; - } - } + if (category) { + content.categoryIdentifier = category; + } - if (sound) { - localNotif.soundName = sound; - } else { - localNotif.soundName = UILocalNotificationDefaultSoundName; - } + if (sound) { + content.sound = [UNNotificationSound soundNamed:sound]; + } else { + content.sound = [UNNotificationSound defaultSound]; + } - if (badge) { - localNotif.applicationIconBadgeNumber = [badge intValue]; - } + if (badge) { + content.badge = [NSNumber numberWithInt:[badge intValue]]; + } - localNotif.userInfo = mutableInfo; + content.userInfo = mutableInfo; - // Schedule the notification - [app scheduleLocalNotification:localNotif]; -#pragma clang diagnostic pop - } + NSDateComponents *dateComponenets = [[NSDateComponents alloc] init]; + [dateComponenets setSecond:countdownSeconds]; + UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponenets repeats:NO]; + + UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:messageId content:content trigger:trigger]; + + [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { + if (error) { + LPLog(LPError, error.localizedDescription); + } + }]; if ([LPConstantsState sharedState].isDevelopmentModeEnabled) { LPLog(LPInfo, @"Scheduled notification"); @@ -190,45 +152,26 @@ - (BOOL)schedule:(LPActionContext *)context - (void)cancelLocalNotification:(NSString *)messageId { LP_END_USER_CODE - UIApplication *app = [UIApplication sharedApplication]; - NSArray *notifications = [app scheduledLocalNotifications]; BOOL canceled = NO; - if (@available(iOS 10.0, *)) { - __block BOOL didCancel = NO; - dispatch_semaphore_t semaphor = dispatch_semaphore_create(0); - [UNUserNotificationCenter.currentNotificationCenter getPendingNotificationRequestsWithCompletionHandler:^(NSArray * _Nonnull requests) { - for (UNNotificationRequest *request in requests) { - NSString *notificationMessageId = [Utilities messageIdFromUserInfo:[request.content userInfo]]; - if ([notificationMessageId isEqualToString:messageId]) { - [UNUserNotificationCenter.currentNotificationCenter removePendingNotificationRequestsWithIdentifiers:@[request.identifier]]; - if ([LPConstantsState sharedState].isDevelopmentModeEnabled) { - LPLog(LPInfo, @"Cancelled notification"); - } - didCancel = YES; - } - } - dispatch_semaphore_signal(semaphor); - }]; - dispatch_time_t waitTime = dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC); - dispatch_semaphore_wait(semaphor, waitTime); - LP_BEGIN_USER_CODE - canceled = didCancel; - } else { - // Fallback on earlier versions - BOOL didCancel = NO; - for (UILocalNotification *notification in notifications) { - NSString *notificationMessageId = [Utilities messageIdFromUserInfo:[notification userInfo]]; + __block BOOL didCancel = NO; + dispatch_semaphore_t semaphor = dispatch_semaphore_create(0); + [UNUserNotificationCenter.currentNotificationCenter getPendingNotificationRequestsWithCompletionHandler:^(NSArray * _Nonnull requests) { + for (UNNotificationRequest *request in requests) { + NSString *notificationMessageId = [Utilities messageIdFromUserInfo:[request.content userInfo]]; if ([notificationMessageId isEqualToString:messageId]) { - [app cancelLocalNotification:notification]; + [UNUserNotificationCenter.currentNotificationCenter removePendingNotificationRequestsWithIdentifiers:@[request.identifier]]; if ([LPConstantsState sharedState].isDevelopmentModeEnabled) { LPLog(LPInfo, @"Cancelled notification"); } didCancel = YES; } } - LP_BEGIN_USER_CODE - canceled = didCancel; - } + dispatch_semaphore_signal(semaphor); + }]; + dispatch_time_t waitTime = dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC); + dispatch_semaphore_wait(semaphor, waitTime); + LP_BEGIN_USER_CODE + canceled = didCancel; if (canceled) { // Track cancel @@ -258,44 +201,27 @@ - (BOOL)shouldDiscard:(NSDate *)eta context:(LPActionContext *)context { // If there's already one scheduled before the eta, discard this. // Otherwise, discard the scheduled one. - if (@available(iOS 10.0, *)) { - __block BOOL shouldDiscard = NO; - dispatch_semaphore_t semaphor = dispatch_semaphore_create(0); - [UNUserNotificationCenter.currentNotificationCenter getPendingNotificationRequestsWithCompletionHandler:^(NSArray * _Nonnull requests) { - for (UNNotificationRequest *request in requests) { - NSString *messageId = [Utilities messageIdFromUserInfo:[request.content userInfo]]; - if ([messageId isEqualToString:context.messageId]) { - UNCalendarNotificationTrigger *trigger = (UNCalendarNotificationTrigger *)request.trigger; - NSComparisonResult comparison = [trigger.nextTriggerDate compare:eta]; - if (comparison == NSOrderedAscending) { - shouldDiscard = YES; - break; - } else { - [UNUserNotificationCenter.currentNotificationCenter removeDeliveredNotificationsWithIdentifiers:@[request.identifier]]; - } - } - } - dispatch_semaphore_signal(semaphor); - }]; - dispatch_time_t waitTime = dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC); - dispatch_semaphore_wait(semaphor, waitTime); - return shouldDiscard; - } else { - // Fallback on earlier versions - NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications]; - for (UILocalNotification *notification in notifications) { - NSString *messageId = [Utilities messageIdFromUserInfo:[notification userInfo]]; + __block BOOL shouldDiscard = NO; + dispatch_semaphore_t semaphor = dispatch_semaphore_create(0); + [UNUserNotificationCenter.currentNotificationCenter getPendingNotificationRequestsWithCompletionHandler:^(NSArray * _Nonnull requests) { + for (UNNotificationRequest *request in requests) { + NSString *messageId = [Utilities messageIdFromUserInfo:[request.content userInfo]]; if ([messageId isEqualToString:context.messageId]) { - NSComparisonResult comparison = [notification.fireDate compare:eta]; + UNCalendarNotificationTrigger *trigger = (UNCalendarNotificationTrigger *)request.trigger; + NSComparisonResult comparison = [trigger.nextTriggerDate compare:eta]; if (comparison == NSOrderedAscending) { - return YES; + shouldDiscard = YES; + break; } else { - [[UIApplication sharedApplication] cancelLocalNotification:notification]; + [UNUserNotificationCenter.currentNotificationCenter removeDeliveredNotificationsWithIdentifiers:@[request.identifier]]; } } } - return NO; - } + dispatch_semaphore_signal(semaphor); + }]; + dispatch_time_t waitTime = dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC); + dispatch_semaphore_wait(semaphor, waitTime); + return shouldDiscard; } #pragma clang diagnostic pop diff --git a/LeanplumSDK/LeanplumSDK/Classes/Utilities/LPUtils.m b/LeanplumSDK/LeanplumSDK/Classes/Utilities/LPUtils.m index 88c8cac1..d4a55ff1 100644 --- a/LeanplumSDK/LeanplumSDK/Classes/Utilities/LPUtils.m +++ b/LeanplumSDK/LeanplumSDK/Classes/Utilities/LPUtils.m @@ -106,17 +106,7 @@ + (void)openURL:(NSURL *)url + (void)openURL:(NSURL *)url completionHandler:(void (^ __nullable)(BOOL success))completion { - if (@available(iOS 10.0, *)) { - [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:completion]; - } else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - [[UIApplication sharedApplication] openURL:url]; - if (completion) { - completion(YES); - } -#pragma clang diagnostic pop - } + [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:completion]; } + (BOOL)isBoolNumber:(NSNumber *)value diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Extensions/UIUserNotificationSettings+Transform.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Extensions/UIUserNotificationSettings+Transform.swift deleted file mode 100644 index dba730db..00000000 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Extensions/UIUserNotificationSettings+Transform.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// UIUserNotificationSettings+Transform.swift -// LeanplumSDK -// -// Copyright (c) 2021 Leanplum, Inc. All rights reserved. -// - -import Foundation - -extension UIUserNotificationSettings { - var dictionary: [AnyHashable: Any] { - let types = self.types - var categories: [String] = [] - if let tmpCategories = self.categories { - for category in tmpCategories { - if let categoryIdentifier = category.identifier { - categories.append(categoryIdentifier) - } - } - } - let sortedCategories = categories.sorted { (lhs: String, rhs: String) -> Bool in - return lhs.caseInsensitiveCompare(rhs) == .orderedAscending - } - let settings = [ - LP_PARAM_DEVICE_USER_NOTIFICATION_TYPES: types.rawValue, - LP_PARAM_DEVICE_USER_NOTIFICATION_CATEGORIES: sortedCategories - ] as [AnyHashable: Any] - return settings - } -} diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Extensions/UNNotificationSettings+Transform.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Extensions/UNNotificationSettings+Transform.swift index 634dec6e..823086b4 100644 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Extensions/UNNotificationSettings+Transform.swift +++ b/LeanplumSDK/LeanplumSDK/ClassesSwift/Extensions/UNNotificationSettings+Transform.swift @@ -7,7 +7,6 @@ import Foundation -@available(iOS 10.0, *) extension UNNotificationSettings { func toInt() -> UInt? { diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NSObject+Notifications.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NSObject+Notifications.swift index fbfa37ac..c3f082c9 100644 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NSObject+Notifications.swift +++ b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NSObject+Notifications.swift @@ -61,12 +61,6 @@ extension NSObject { // Call method directly since the it requires 3 objects and performSelector supports only 2 // otherwise use Method IMP self.leanplum_application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler) - } else { - leanplumCompletionHandler = completionHandler - - if notificationsProxy.shouldFallbackToLegacyMethods { - notificationsProxy.appDelegate?.application?(UIApplication.shared, didReceiveRemoteNotification: userInfo) - } } // Call completion handler @@ -121,7 +115,7 @@ extension NSObject { } // MARK: - UserNotificationCenter - @objc @available(iOS 10.0, *) + @objc func leanplum_userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { @@ -163,8 +157,8 @@ extension NSObject { } } } - - @objc @available(iOS 10.0, *) + + @objc func leanplum_userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { @@ -183,38 +177,4 @@ extension NSObject { // Notification is received while app is running on foreground Leanplum.notificationsManager().notificationReceived(userInfo: notification.request.content.userInfo, isForeground: true) } - - // MARK: - didReceive Local Notification - @objc func leanplum_application(_ application: UIApplication, didReceive notification: UILocalNotification) { - Log.debug("Called swizzled application:didReceive:localNotification") - - defer { - // Call overridden method - let selector = #selector(self.leanplum_application(_:didReceive:)) - if swizzling.applicationDidReceiveLocalNotification && self.responds(to: selector) { - self.perform(selector, with: application, with: notification) - } - } - - guard let userInfo = notification.userInfo else { - return - } - - if UIApplication.shared.applicationState == .active { - Leanplum.notificationsManager().notificationReceived(userInfo: userInfo, isForeground: true) - } else { - Leanplum.notificationsManager().notificationOpened(userInfo: userInfo) - } - } - - // MARK: - didRegister Notification Settings - @objc func leanplum_application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { - Leanplum.notificationsManager().didRegister(notificationSettings) - - // Call overridden method - let selector = #selector(self.leanplum_application(_:didRegister:)) - if swizzling.applicationDidRegisterUserNotificationSettings && self.responds(to: selector) { - self.perform(selector, with: application, with: notificationSettings) - } - } } diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationSettings.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationSettings.swift index c87b2fa1..fc6f4123 100644 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationSettings.swift +++ b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationSettings.swift @@ -10,30 +10,20 @@ import Foundation class NotificationSettings { func getSettings(updateToServer: Bool = false, completionHandler: ((_ settings: [AnyHashable: Any], _ areChanged: Bool)->())? = nil) { - if #available(iOS 10.0, *) { - self.getSettingsFromUserNotification { [weak self] settings in - guard let self = self else { - completionHandler?([:], false) - return - } - var settings_: [AnyHashable: Any] = [:] - for item in settings { - settings_[item.key] = item.value != nil ? item.value : nil - } - let changed = !settings_.isEqual(Leanplum.user.notificationSettings ?? [:]) - if changed { - self.updateSettings(settings_, updateToServer: updateToServer) - } - completionHandler?(settings_, changed) + self.getSettingsFromUserNotification { [weak self] settings in + guard let self = self else { + completionHandler?([:], false) + return + } + var settings_: [AnyHashable: Any] = [:] + for item in settings { + settings_[item.key] = item.value != nil ? item.value : nil } - } else { - // Fallback on earlier versions - let settings = getSettingsFromUIApplication() - let changed = !settings.isEqual(Leanplum.user.notificationSettings ?? [:]) + let changed = !settings_.isEqual(Leanplum.user.notificationSettings ?? [:]) if changed { - updateSettings(settings, updateToServer: updateToServer) + self.updateSettings(settings_, updateToServer: updateToServer) } - completionHandler?(settings, changed) + completionHandler?(settings_, changed) } } @@ -55,7 +45,6 @@ class NotificationSettings { } } - @available(iOS 10.0, *) private func getSettingsFromUserNotification(completionHandler: @escaping (_ settings: [AnyHashable: Any?])->()) { UNUserNotificationCenter.current().getNotificationSettings { settings in let types = settings.toInt() @@ -77,12 +66,4 @@ class NotificationSettings { } } } - - /// Retrieves notification settings from UIApplication. Used for iOS9 devices (older than iOS 10) - private func getSettingsFromUIApplication() -> [AnyHashable: Any] { - guard let settings = UIApplication.shared.currentUserNotificationSettings?.dictionary else { - return [:] - } - return settings - } } diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationsManager+Utilities.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationsManager+Utilities.swift index f5be7077..f6fd6a30 100644 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationsManager+Utilities.swift +++ b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationsManager+Utilities.swift @@ -43,25 +43,19 @@ import Foundation block() return } - if #available(iOS 10.0, *) { - UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in - if let error = error { - // Handle the error here. - Log.error("Error: \(error.localizedDescription)") - } - - // Register for remote notification to create and send push token to server - // no metter if the request was granted or has error, push token will be generated - // and later if user decides to go into the settings and enables push notifications - // we will have token and will only update push types - DispatchQueue.main.async { - UIApplication.shared.registerForRemoteNotifications() - } + UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in + if let error = error { + // Handle the error here. + Log.error("Error: \(error.localizedDescription)") + } + + // Register for remote notification to create and send push token to server + // no metter if the request was granted or has error, push token will be generated + // and later if user decides to go into the settings and enables push notifications + // we will have token and will only update push types + DispatchQueue.main.async { + UIApplication.shared.registerForRemoteNotifications() } - } else if #available(iOS 8.0, *) { - UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], - categories: nil)) - UIApplication.shared.registerForRemoteNotifications() } } diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationsManager.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationsManager.swift index c92f1a04..bbd6f38e 100644 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationsManager.swift +++ b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/NotificationsManager.swift @@ -33,13 +33,6 @@ import UIKit notificationSettings.getSettings(completionHandler: completionHandler) } - @available(iOS, deprecated: 10.0) - @objc(didRegisterUserNotificationSettings:) - public func didRegister(_ settings: UIUserNotificationSettings) { - isAskToAskDisabled = true - notificationSettings.getSettings() - } - // MARK: - Push Token @objc public func didRegisterForRemoteNotificationsWithDeviceToken(_ deviceToken: Data) { isAskToAskDisabled = true diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+Disabled.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+Disabled.swift index 27d1d6f4..06fb7de7 100644 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+Disabled.swift +++ b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+Disabled.swift @@ -18,30 +18,16 @@ extension NotificationsProxy { @objc public func didReceiveRemoteNotification(userInfo: [AnyHashable: Any], fetchCompletionHandler: @escaping (UIBackgroundFetchResult) -> Void) { self.leanplum_application(UIApplication.shared, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: fetchCompletionHandler) } - - @available(iOS 10.0, *) + @objc public func userNotificationCenter(didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { self.leanplum_userNotificationCenter(UNUserNotificationCenter.current(), didReceive: response, withCompletionHandler: completionHandler) } - - @available(iOS 10.0, *) + @objc public func userNotificationCenter(willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { self.leanplum_userNotificationCenter(UNUserNotificationCenter.current(), willPresent: notification, withCompletionHandler: completionHandler) } - @available(iOS, deprecated: 10.0) - @objc public func application(didReceive notification: UILocalNotification) { - self.leanplum_application(UIApplication.shared, didReceive: notification) - } - @objc public func handleActionWithIdentifier(_ identifier: String, forRemoteNotification notification: [AnyHashable:Any]) { Leanplum.notificationsManager().notificationOpened(userInfo: notification, action: identifier) } - - @available(iOS, deprecated: 10.0) - @objc public func handleActionWithIdentifier(_ identifier: String, forLocalNotification notification: UILocalNotification) { - if let userInfo = notification.userInfo { - Leanplum.notificationsManager().notificationOpened(userInfo: userInfo, action: identifier) - } - } } diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+Swizzling.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+Swizzling.swift index dfabff3e..57949d6b 100644 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+Swizzling.swift +++ b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+Swizzling.swift @@ -67,7 +67,6 @@ extension NotificationsProxy { } // MARK: - Swizzle UNUserNotificationCenter methods - @available(iOS 10.0, *) func swizzleUNUserNotificationCenterMethods() { // userNotificationCenter:didReceive:withCompletionHandler: let userNotificationCenterDidReceiveNotificationResponseWithCompletionHandlerSelector = #selector(UNUserNotificationCenterDelegate.userNotificationCenter(_:didReceive:withCompletionHandler:)) diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+iOS9.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+iOS9.swift deleted file mode 100644 index a4245fe2..00000000 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy+iOS9.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// NotificationsProxy+iOS9.swift -// LeanplumSDK -// -// Created by Nikola Zagorchev on 23.12.21. -// Copyright © 2021 Leanplum. All rights reserved. - -import Foundation - -extension NotificationsProxy { - /// Check if didReceiveRemoteNotification is implemented (deprecated in iOS 10). - /// If :didReceiveRemoteNotification:fetchCompletionHandler: is implemented the above mentioned method - /// will not be called - func hasImplementedApplicationDidReceive() -> Bool { - let applicationDidReceiveRemoteNotificationSelector = #selector(UIApplicationDelegate.application(_:didReceiveRemoteNotification:)) - let applicationDidReceiveRemoteNotificationMethod = class_getInstanceMethod(appDelegateClass, - applicationDidReceiveRemoteNotificationSelector) - return applicationDidReceiveRemoteNotificationMethod != nil - } - - /// Swizzle Local Notification method - func swizzleLocalNotificationMethods() { - // Detect local notifications while app is running - let applicationDidReceiveLocalNotification = #selector(UIApplicationDelegate.application(_:didReceive:)) - let leanplum_applicationDidReceiveLocalNotification = #selector(leanplum_application(_:didReceive:)) - swizzled.applicationDidReceiveLocalNotification = LPSwizzle.hook(into: applicationDidReceiveLocalNotification, - with: leanplum_applicationDidReceiveLocalNotification, - for: appDelegateClass) - } - - /// Swizzle Notification Settings method - func swizzleUserNotificationSettings() { - let applicationDidRegisterUserNotificationSettings = #selector(UIApplicationDelegate.application(_:didRegister:)) - let leanplum_applicationDidRegisterUserNotificationSettings = #selector(leanplum_application(_:didRegister:)) - swizzled.applicationDidRegisterUserNotificationSettings = LPSwizzle.hook(into: applicationDidRegisterUserNotificationSettings, - with: leanplum_applicationDidRegisterUserNotificationSettings, - for: appDelegateClass) - } -} diff --git a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy.swift b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy.swift index e88767b8..66b878e4 100644 --- a/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy.swift +++ b/LeanplumSDK/LeanplumSDK/ClassesSwift/Notifications/Proxy/NotificationsProxy.swift @@ -24,7 +24,7 @@ public class NotificationsProxy: NSObject { var isCustomAppDelegateUsed = false private var pushNotificationPresentationOptionWrapper: Any? - @objc @available(iOS 10.0, *) + @objc // UNNotificationPresentationOptionNone public var pushNotificationPresentationOption: UNNotificationPresentationOptions { get { @@ -78,13 +78,6 @@ public class NotificationsProxy: NSObject { notificationOpenedFromStart = true Leanplum.notificationsManager().notificationOpened(userInfo: remoteNotification, action: LP_VALUE_DEFAULT_PUSH_ACTION, fromLaunch: true) } - } else if - let localNotification = - launchOptions[UIApplication.LaunchOptionsKey.localNotification] as? UILocalNotification, - let userInfo = localNotification.userInfo { - notificationHandledFromStart = userInfo - notificationOpenedFromStart = true - Leanplum.notificationsManager().notificationOpened(userInfo: userInfo) } } @@ -108,34 +101,18 @@ public class NotificationsProxy: NSObject { // Token methods are version agnostic swizzleTokenMethods() - - // Try to swizzle UNUserNotificationCenterDelegate methods - if #available(iOS 10.0, *) { - // Client's UNUserNotificationCenter delegate needs to be set before Leanplum starts - swizzleUNUserNotificationCenterMethods() - swizzleApplicationDidReceiveFetchCompletionHandler() - if !swizzled.applicationDidReceiveRemoteNotificationWithCompletionHandler { - // if background modes / content-available:1, swizzle for prefetch - swizzleApplicationDidReceiveFetchCompletionHandler(true) - } else if !hasImplementedNotificationCenterMethods { - // application:didReceiveRemoteNotification:fetchCompletionHandler: method is implemented and - // notificationCenter methods are not, we need to call that method manually, - // since we set our own notification center delegate - shouldFallbackToLegacyMethods = true - } - } else { - swizzleUserNotificationSettings() - swizzleLocalNotificationMethods() - - swizzleApplicationDidReceiveFetchCompletionHandler() - if !swizzled.applicationDidReceiveRemoteNotificationWithCompletionHandler { - // if it is not swizzled, add an implementation to listen for notifications - swizzleApplicationDidReceiveFetchCompletionHandler(true) - if hasImplementedApplicationDidReceive() { - // need to call legacy - shouldFallbackToLegacyMethods = true - } - } + + // Client's UNUserNotificationCenter delegate needs to be set before Leanplum starts + swizzleUNUserNotificationCenterMethods() + swizzleApplicationDidReceiveFetchCompletionHandler() + if !swizzled.applicationDidReceiveRemoteNotificationWithCompletionHandler { + // if background modes / content-available:1, swizzle for prefetch + swizzleApplicationDidReceiveFetchCompletionHandler(true) + } else if !hasImplementedNotificationCenterMethods { + // application:didReceiveRemoteNotification:fetchCompletionHandler: method is implemented and + // notificationCenter methods are not, we need to call that method manually, + // since we set our own notification center delegate + shouldFallbackToLegacyMethods = true } } } diff --git a/LeanplumSDKApp/LeanplumSDKApp.xcodeproj/project.pbxproj b/LeanplumSDKApp/LeanplumSDKApp.xcodeproj/project.pbxproj index bda88fbb..907992e1 100644 --- a/LeanplumSDKApp/LeanplumSDKApp.xcodeproj/project.pbxproj +++ b/LeanplumSDKApp/LeanplumSDKApp.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -1205,7 +1205,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -1260,7 +1260,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; diff --git a/LeanplumSDKApp/LeanplumSDKTests/Classes/Notifications/PushNotificationSettingsTest.swift b/LeanplumSDKApp/LeanplumSDKTests/Classes/Notifications/PushNotificationSettingsTest.swift index 65ffbb1f..ad756a8a 100644 --- a/LeanplumSDKApp/LeanplumSDKTests/Classes/Notifications/PushNotificationSettingsTest.swift +++ b/LeanplumSDKApp/LeanplumSDKTests/Classes/Notifications/PushNotificationSettingsTest.swift @@ -10,7 +10,6 @@ import Foundation import XCTest @testable import Leanplum -@available(iOS 10.0, *) class PushNotificationSettingsTest: XCTestCase { var notificationSettings: NotificationSettings! @@ -168,7 +167,6 @@ extension NotificationSettings: NotificationSettingsProtocol { } } -@available(iOS 10.0, *) extension UNUserNotificationCenter { static var originalMethod: OpaquePointer? static var swizzledMethod: OpaquePointer? @@ -195,7 +193,6 @@ extension UNUserNotificationCenter { } } -@available(iOS 10.0, *) extension UNNotificationSettings { static var fakeAuthorizationStatus: UNAuthorizationStatus = .authorized @@ -222,7 +219,6 @@ extension UNNotificationSettings { } } -@available(iOS 10.0, *) class MockNSCoder: NSCoder { var authorizationStatus = UNAuthorizationStatus.authorized.rawValue diff --git a/LeanplumSDKLocation/LeanplumSDKLocation.xcodeproj/project.pbxproj b/LeanplumSDKLocation/LeanplumSDKLocation.xcodeproj/project.pbxproj index 47daf303..e72320d9 100644 --- a/LeanplumSDKLocation/LeanplumSDKLocation.xcodeproj/project.pbxproj +++ b/LeanplumSDKLocation/LeanplumSDKLocation.xcodeproj/project.pbxproj @@ -546,7 +546,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 15.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -602,7 +602,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 15.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -626,7 +626,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -664,7 +663,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -705,7 +703,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -743,7 +740,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -778,7 +774,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -814,7 +809,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -853,7 +847,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -891,7 +884,6 @@ GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/Podfile b/Podfile index 27854dcf..f41d0e8e 100644 --- a/Podfile +++ b/Podfile @@ -1,4 +1,4 @@ -platform :ios, '9.0' +platform :ios, '10.0' use_modular_headers! workspace 'Leanplum.xcworkspace'