Skip to content

Commit

Permalink
Code cleanup after dropping support for iOS 11
Browse files Browse the repository at this point in the history
Reviewed By: samodom

Differential Revision: D39673870

fbshipit-source-id: 37b62ed9a6360a3f96fbbd5cd6c595af3e72d156
  • Loading branch information
jawwad authored and facebook-github-bot committed Sep 20, 2022
1 parent 48dd997 commit 582fd1d
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 135 deletions.
24 changes: 11 additions & 13 deletions FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -974,19 +974,17 @@ - (void)fetchServerConfiguration:(FBSDKCodeBlock)callback
[self.onDeviceMLModelManager enable];
}
}];
if (@available(iOS 11.3, *)) {
if ([self.settings isSKAdNetworkReportEnabled]) {
[self.featureChecker checkFeature:FBSDKFeatureSKAdNetwork completionBlock:^(BOOL SKAdNetworkEnabled) {
if (SKAdNetworkEnabled) {
[SKAdNetwork registerAppForAdNetworkAttribution];
[self.featureChecker checkFeature:FBSDKFeatureSKAdNetworkConversionValue completionBlock:^(BOOL SKAdNetworkConversionValueEnabled) {
if (SKAdNetworkConversionValueEnabled) {
[self.skAdNetworkReporter enable];
}
}];
}
}];
}
if ([self.settings isSKAdNetworkReportEnabled]) {
[self.featureChecker checkFeature:FBSDKFeatureSKAdNetwork completionBlock:^(BOOL SKAdNetworkEnabled) {
if (SKAdNetworkEnabled) {
[SKAdNetwork registerAppForAdNetworkAttribution];
[self.featureChecker checkFeature:FBSDKFeatureSKAdNetworkConversionValue completionBlock:^(BOOL SKAdNetworkConversionValueEnabled) {
if (SKAdNetworkConversionValueEnabled) {
[self.skAdNetworkReporter enable];
}
}];
}
}];
}
if (@available(iOS 14.0, *)) {
[self.featureChecker checkFeature:FBSDKFeatureAEM completionBlock:^(BOOL AEMEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,9 @@ - (void) configureWithStore:(id<FBSDKDataPersisting>)store
self.graphRequestConnectionFactory = graphRequestConnectionFactory;
id data = [self.store fb_objectForKey:FBSDKAppEventsConfigurationKey];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([data isKindOfClass:NSData.class]) {
if (@available(iOS 11.0, tvOS 11.0, *)) {
self.configuration = [NSKeyedUnarchiver unarchivedObjectOfClass:FBSDKAppEventsConfiguration.class fromData:data error:nil];
} else {
self.configuration = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
self.configuration = [NSKeyedUnarchiver unarchivedObjectOfClass:FBSDKAppEventsConfiguration.class fromData:data error:nil];
}
#pragma clang diagnostic pop

if (!self.configuration) {
self.configuration = FBSDKAppEventsConfiguration.defaultConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ - (void)logTransactionEvent:(SKProduct *)product
- (BOOL)isSubscription:(SKProduct *)product
{
#if !TARGET_OS_TV
if (@available(iOS 11.2, *)) {
return (product.subscriptionPeriod != nil) && ((unsigned long)product.subscriptionPeriod.numberOfUnits > 0);
}
#endif
return (product.subscriptionPeriod != nil) && ((unsigned long)product.subscriptionPeriod.numberOfUnits > 0);
#else
return NO;
#endif
}

- (NSMutableDictionary<NSString *, id> *)getEventParametersOfProduct:(SKProduct *)product
Expand Down Expand Up @@ -184,26 +183,24 @@ - (BOOL)isSubscription:(SKProduct *)product
}

#if !TARGET_OS_TV
if (@available(iOS 11.2, *)) {
if ([self isSubscription:product]) {
// subs inapp
[FBSDKTypeUtility dictionary:eventParameters setObject:[self durationOfSubscriptionPeriod:product.subscriptionPeriod] forKey:FBSDKAppEventParameterNameSubscriptionPeriod];
[FBSDKTypeUtility dictionary:eventParameters setObject:@"subs" forKey:FBSDKAppEventParameterNameInAppPurchaseType];
[FBSDKTypeUtility dictionary:eventParameters setObject:[self isStartTrial:transaction ofProduct:product] ? @"1" : @"0" forKey:FBSDKAppEventParameterNameIsStartTrial];
// trial information for subs
SKProductDiscount *discount = product.introductoryPrice;
if (discount) {
if (discount.paymentMode == SKProductDiscountPaymentModeFreeTrial) {
[FBSDKTypeUtility dictionary:eventParameters setObject:@"1" forKey:FBSDKAppEventParameterNameHasFreeTrial];
} else {
[FBSDKTypeUtility dictionary:eventParameters setObject:@"0" forKey:FBSDKAppEventParameterNameHasFreeTrial];
}
[FBSDKTypeUtility dictionary:eventParameters setObject:[self durationOfSubscriptionPeriod:discount.subscriptionPeriod] forKey:FBSDKAppEventParameterNameTrialPeriod];
[FBSDKTypeUtility dictionary:eventParameters setObject:discount.price forKey:FBSDKAppEventParameterNameTrialPrice];
if ([self isSubscription:product]) {
// subs inapp
[FBSDKTypeUtility dictionary:eventParameters setObject:[self durationOfSubscriptionPeriod:product.subscriptionPeriod] forKey:FBSDKAppEventParameterNameSubscriptionPeriod];
[FBSDKTypeUtility dictionary:eventParameters setObject:@"subs" forKey:FBSDKAppEventParameterNameInAppPurchaseType];
[FBSDKTypeUtility dictionary:eventParameters setObject:[self isStartTrial:transaction ofProduct:product] ? @"1" : @"0" forKey:FBSDKAppEventParameterNameIsStartTrial];
// trial information for subs
SKProductDiscount *discount = product.introductoryPrice;
if (discount) {
if (discount.paymentMode == SKProductDiscountPaymentModeFreeTrial) {
[FBSDKTypeUtility dictionary:eventParameters setObject:@"1" forKey:FBSDKAppEventParameterNameHasFreeTrial];
} else {
[FBSDKTypeUtility dictionary:eventParameters setObject:@"0" forKey:FBSDKAppEventParameterNameHasFreeTrial];
}
} else {
[FBSDKTypeUtility dictionary:eventParameters setObject:@"inapp" forKey:FBSDKAppEventParameterNameInAppPurchaseType];
[FBSDKTypeUtility dictionary:eventParameters setObject:[self durationOfSubscriptionPeriod:discount.subscriptionPeriod] forKey:FBSDKAppEventParameterNameTrialPeriod];
[FBSDKTypeUtility dictionary:eventParameters setObject:discount.price forKey:FBSDKAppEventParameterNameTrialPrice];
}
} else {
[FBSDKTypeUtility dictionary:eventParameters setObject:@"inapp" forKey:FBSDKAppEventParameterNameInAppPurchaseType];
}
#endif
return eventParameters;
Expand Down Expand Up @@ -246,15 +243,13 @@ - (BOOL)isStartTrial:(SKPaymentTransaction *)transaction
}
}
}
// introductory offer starting from iOS 11.2
if (@available(iOS 11.2, *)) {
if (product.introductoryPrice
&& product.introductoryPrice.paymentMode == SKProductDiscountPaymentModeFreeTrial) {
NSString *originalTransactionID = transaction.originalTransaction.transactionIdentifier;
// only consider the very first trial transaction as start trial
if (!originalTransactionID) {
return YES;
}

if (product.introductoryPrice
&& product.introductoryPrice.paymentMode == SKProductDiscountPaymentModeFreeTrial) {
NSString *originalTransactionID = transaction.originalTransaction.transactionIdentifier;
// only consider the very first trial transaction as start trial
if (!originalTransactionID) {
return YES;
}
}
#endif
Expand All @@ -264,18 +259,16 @@ - (BOOL)isStartTrial:(SKPaymentTransaction *)transaction
- (nullable NSString *)durationOfSubscriptionPeriod:(id)subcriptionPeriod
{
#if !TARGET_OS_TV
if (@available(iOS 11.2, *)) {
if (subcriptionPeriod && [subcriptionPeriod isKindOfClass:SKProductSubscriptionPeriod.class]) {
SKProductSubscriptionPeriod *period = (SKProductSubscriptionPeriod *)subcriptionPeriod;
NSString *unit = nil;
switch (period.unit) {
case SKProductPeriodUnitDay: unit = @"D"; break;
case SKProductPeriodUnitWeek: unit = @"W"; break;
case SKProductPeriodUnitMonth: unit = @"M"; break;
case SKProductPeriodUnitYear: unit = @"Y"; break;
}
return [NSString stringWithFormat:@"P%lu%@", (unsigned long)period.numberOfUnits, unit];
if (subcriptionPeriod && [subcriptionPeriod isKindOfClass:SKProductSubscriptionPeriod.class]) {
SKProductSubscriptionPeriod *period = (SKProductSubscriptionPeriod *)subcriptionPeriod;
NSString *unit = nil;
switch (period.unit) {
case SKProductPeriodUnitDay: unit = @"D"; break;
case SKProductPeriodUnitWeek: unit = @"W"; break;
case SKProductPeriodUnitMonth: unit = @"M"; break;
case SKProductPeriodUnitYear: unit = @"Y"; break;
}
return [NSString stringWithFormat:@"P%lu%@", (unsigned long)period.numberOfUnits, unit];
}
#endif
return nil;
Expand Down
14 changes: 4 additions & 10 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKBridgeAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#import "FBSDKLogger+Internal.h"
#import "FBSDKURLScheme.h"

/// Specifies state of FBSDKAuthenticationSession (SFAuthenticationSession (iOS 11) and ASWebAuthenticationSession (iOS 12+))
/// Specifies state of FBSDKAuthenticationSession
typedef NS_ENUM(NSUInteger, FBSDKAuthenticationSession) {
/// There is no active authentication session
FBSDKAuthenticationSessionNone,
Expand Down Expand Up @@ -62,8 +62,8 @@ @interface FBSDKBridgeAPI () <FBSDKContainerViewControllerDelegate, ASWebAuthent
@property (nonatomic) NSObject<FBSDKBridgeAPIRequest> *pendingRequest;
@property (nonatomic) FBSDKBridgeAPIResponseBlock pendingRequestCompletionBlock;
@property (nonatomic) id<FBSDKURLOpening> pendingURLOpen;
@property (nonatomic) id<FBSDKAuthenticationSession> authenticationSession NS_AVAILABLE_IOS(11_0);
@property (nonatomic) FBSDKAuthenticationCompletionHandler authenticationSessionCompletionHandler NS_AVAILABLE_IOS(11_0);
@property (nonatomic) id<FBSDKAuthenticationSession> authenticationSession;
@property (nonatomic) FBSDKAuthenticationCompletionHandler authenticationSessionCompletionHandler;
@property (nonatomic) FBSDKAuthenticationSession authenticationSessionState;
@property (nonatomic) BOOL expectingBackground;
@property (nullable, nonatomic) SFSafariViewController *safariViewController;
Expand Down Expand Up @@ -125,13 +125,7 @@ - (void)applicationDidBecomeActive:(UIApplication *)application
} else if (_authenticationSession && _authenticationSessionState == FBSDKAuthenticationSessionCanceledBySystem) {
[_authenticationSession cancel];
_authenticationSession = nil;
NSString *errorDomain;
if (@available(iOS 12.0, *)) {
errorDomain = @"com.apple.AuthenticationServices.WebAuthenticationSession";
} else {
errorDomain = @"com.apple.SafariServices.Authentication";
}

NSString *errorDomain = @"com.apple.AuthenticationServices.WebAuthenticationSession";
NSError *error = [self.errorFactory errorWithDomain:errorDomain
code:1
userInfo:nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,11 @@ final class CoreKitComponents {
}

var skAdNetworkReporter: (_AppEventsReporter & SKAdNetworkReporting)?
if #available(iOS 11.3, *) {
skAdNetworkReporter = _SKAdNetworkReporter(
graphRequestFactory: graphRequestFactory,
dataStore: UserDefaults.standard,
conversionValueUpdater: SKAdNetwork.self
)
}
skAdNetworkReporter = _SKAdNetworkReporter(
graphRequestFactory: graphRequestFactory,
dataStore: UserDefaults.standard,
conversionValueUpdater: SKAdNetwork.self
)

let metaIndexer: _MetadataIndexing = _MetadataIndexer(userDataStore: userDataStore, swizzler: _Swizzler.self)
let suggestedEventsIndexer: _SuggestedEventsIndexerProtocol = _SuggestedEventsIndexer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,7 @@ + (void)processLoadRequestResponse:(id)result error:(NSError *)error
NSString *defaultKey = [NSString stringWithFormat:FBSDK_GATEKEEPERS_USER_DEFAULTS_KEY,
_settings.appID];

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_11_0
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:gateKeeper requiringSecureCoding:NO error:NULL];
#else
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:gateKeeper];
#endif

[self.store fb_setObject:data forKey:defaultKey];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ final class DefaultCoreKitComponentsTests: XCTestCase {
)
}

@available(iOS 11.3, *)
func testSKAdNetworkReporter() throws {
let reporter = try XCTUnwrap(
components.skAdNetworkReporter as? _SKAdNetworkReporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Security
import Social
import XCTest

@available(iOS 12.0, *)
final class DynamicFrameworkLoaderTests: XCTestCase {

#if BUCK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NS_SWIFT_NAME(AuthenticationSessionHandling)

@end

/// Specifies state of FBSDKAuthenticationSession (SFAuthenticationSession (iOS 11) and ASWebAuthenticationSession (iOS 12+))
/// Specifies state of FBSDKAuthenticationSession
typedef NS_ENUM(NSUInteger, FBSDKAuthenticationSession) {
/// There is no active authentication session
FBSDKAuthenticationSessionNone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,19 +1194,17 @@ final class AppEventsTests: XCTestCase {
}

func testLogEventWillRecordAndUpdateWithSKAdNetworkReporter() {
if #available(iOS 11.3, *) {
appEvents.logEvent(eventName, valueToSum: purchaseAmount)
XCTAssertEqual(
eventName.rawValue,
skAdNetworkReporter.capturedEvent,
"Logging a event should invoke the SKAdNetwork reporter with the expected event name"
)
XCTAssertEqual(
purchaseAmount,
skAdNetworkReporter.capturedValue?.doubleValue,
"Logging a event should invoke the SKAdNetwork reporter with the expected event value"
)
}
appEvents.logEvent(eventName, valueToSum: purchaseAmount)
XCTAssertEqual(
eventName.rawValue,
skAdNetworkReporter.capturedEvent,
"Logging a event should invoke the SKAdNetwork reporter with the expected event name"
)
XCTAssertEqual(
purchaseAmount,
skAdNetworkReporter.capturedValue?.doubleValue,
"Logging a event should invoke the SKAdNetwork reporter with the expected event value"
)
validateAEMReporterCalled(
eventName: eventName,
currency: nil,
Expand Down Expand Up @@ -1456,44 +1454,40 @@ final class AppEventsTests: XCTestCase {
appEvents.fetchServerConfiguration(nil)
appEventsConfigurationProvider.firstCapturedBlock?()
serverConfigurationProvider.capturedCompletionBlock?(nil, nil)
if #available(iOS 11.3, *) {
featureManager.completeCheck(
forFeature: .skAdNetwork,
with: true
)
featureManager.completeCheck(
forFeature: .skAdNetworkConversionValue,
with: true
)
XCTAssertTrue(
skAdNetworkReporter.enableWasCalled,
"""
Fetching a configuration should enable SKAdNetworkReporter when SKAdNetworkReport \
and SKAdNetworkConversionValue are enabled
"""
)
}
featureManager.completeCheck(
forFeature: .skAdNetwork,
with: true
)
featureManager.completeCheck(
forFeature: .skAdNetworkConversionValue,
with: true
)
XCTAssertTrue(
skAdNetworkReporter.enableWasCalled,
"""
Fetching a configuration should enable SKAdNetworkReporter when SKAdNetworkReport \
and SKAdNetworkConversionValue are enabled
"""
)
}

func testFetchingConfigurationDoesNotEnableSKAdNetworkReporterWhenSKAdNetworkConversionValueIsDisabled() {
settings.isSKAdNetworkReportEnabled = true
appEvents.fetchServerConfiguration(nil)
appEventsConfigurationProvider.firstCapturedBlock?()
serverConfigurationProvider.capturedCompletionBlock?(nil, nil)
if #available(iOS 11.3, *) {
featureManager.completeCheck(
forFeature: .skAdNetwork,
with: true
)
featureManager.completeCheck(
forFeature: .skAdNetworkConversionValue,
with: false
)
XCTAssertFalse(
skAdNetworkReporter.enableWasCalled,
"Fetching a configuration should NOT enable SKAdNetworkReporter if SKAdNetworkConversionValue is disabled"
)
}
featureManager.completeCheck(
forFeature: .skAdNetwork,
with: true
)
featureManager.completeCheck(
forFeature: .skAdNetworkConversionValue,
with: false
)
XCTAssertFalse(
skAdNetworkReporter.enableWasCalled,
"Fetching a configuration should NOT enable SKAdNetworkReporter if SKAdNetworkConversionValue is disabled"
)
}

func testFetchingConfigurationNotIncludingSKAdNetworkIfSKAdNetworkReportDisabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/

@available(iOS 11.2, *)
enum SampleProducts {
static func createValid() -> TestProduct {
TestProduct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/

@available(iOS 11.2, *)
final class TestProduct: SKProduct {
static let title = "Product title"
static let productDescription = "Some description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/

@available(iOS 11.2, *)
final class TestProductDiscount: SKProductDiscount {
let stubbedIdentifier: String
let stubbedPaymentMode: PaymentMode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/

@available(iOS 11.2, *)
final class TestProductSubscriptionPeriod: SKProductSubscriptionPeriod {
let stubbedNumberOfUnits: Int

Expand Down

0 comments on commit 582fd1d

Please sign in to comment.