Skip to content

Commit

Permalink
Migrate logger (#592)
Browse files Browse the repository at this point in the history
* Add APITester target

- Added an `APITester` target that relies on the project's public API
- Added build phase run step that builds the `APITester` after the `Purchases` framework
- If the `APITester` target fails, that means we changed the public API

* Update project.pbxproj

Circular dependencies... let's just do a new circle CI step for the target.

* Update dependency

Forgot to update this dependency 🤦‍♂️

* Migrate the logger

Resolves #559

* Fix build

* Don't try and verify bitcode for the APITester project

* Add a swift file

Because apparently this is a thing.

* Update TODOs and messaging to make intentions more clear
  • Loading branch information
taquitos authored Jun 25, 2021
1 parent cd5efee commit 49acaa2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 109 deletions.
4 changes: 4 additions & 0 deletions PublicSDKAPITester/APITester-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

12 changes: 12 additions & 0 deletions PublicSDKAPITester/APITester.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// APITester.swift
// APITester
//
// Created by Joshua Liebowitz on 6/24/21.
// Copyright © 2021 Purchases. All rights reserved.
//

import Foundation

// This file is empty, but is needed so that Xcode can correctly
// link Swift dependencies for the framework.
23 changes: 12 additions & 11 deletions PublicSDKAPITester/RevenueCatAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "RCPurchases.h"

@import StoreKit;
@import PurchasesCoreSwift;

@implementation RevenueCatAPI

Expand All @@ -31,15 +32,17 @@ @implementation RevenueCatAPI
BOOL isAnonymous;

+ (void)allTheThings {
// typedef void (^RCReceivePurchaserInfoBlock)(RCPurchaserInfo * _Nullable, NSError * _Nullable) NS_SWIFT_NAME(Purchases.ReceivePurchaserInfoBlock);
// typedef void (^RCReceiveIntroEligibilityBlock)(NSDictionary<NSString *, RCIntroEligibility *> *) NS_SWIFT_NAME(Purchases.ReceiveIntroEligibilityBlock);
// typedef void (^RCReceiveOfferingsBlock)(RCOfferings * _Nullable, NSError * _Nullable) NS_SWIFT_NAME(Purchases.ReceiveOfferingsBlock);
// typedef void (^RCReceiveProductsBlock)(NSArray<SKProduct *> *) NS_SWIFT_NAME(Purchases.ReceiveProductsBlock);
// typedef void (^RCPurchaseCompletedBlock)(SKPaymentTransaction * _Nullable, RCPurchaserInfo * _Nullable, NSError * _Nullable, BOOL userCancelled) NS_SWIFT_NAME(Purchases.PurchaseCompletedBlock);
// typedef void (^RCDeferredPromotionalPurchaseBlock)(RCPurchaseCompletedBlock);
// typedef void (^RCPaymentDiscountBlock)(SKPaymentDiscount * _Nullable, NSError * _Nullable) NS_SWIFT_NAME(Purchases.PaymentDiscountBlock);
// TODO: Addresses these blocks
// typedef void (^RCReceivePurchaserInfoBlock)(RCPurchaserInfo * _Nullable, NSError * _Nullable) NS_SWIFT_NAME(Purchases.ReceivePurchaserInfoBlock);
// typedef void (^RCReceiveIntroEligibilityBlock)(NSDictionary<NSString *, RCIntroEligibility *> *) NS_SWIFT_NAME(Purchases.ReceiveIntroEligibilityBlock);
// typedef void (^RCReceiveOfferingsBlock)(RCOfferings * _Nullable, NSError * _Nullable) NS_SWIFT_NAME(Purchases.ReceiveOfferingsBlock);
// typedef void (^RCReceiveProductsBlock)(NSArray<SKProduct *> *) NS_SWIFT_NAME(Purchases.ReceiveProductsBlock);
// typedef void (^RCPurchaseCompletedBlock)(SKPaymentTransaction * _Nullable, RCPurchaserInfo * _Nullable, NSError * _Nullable, BOOL userCancelled) NS_SWIFT_NAME(Purchases.PurchaseCompletedBlock);
// typedef void (^RCDeferredPromotionalPurchaseBlock)(RCPurchaseCompletedBlock);
// typedef void (^RCPaymentDiscountBlock)(SKPaymentDiscount * _Nullable, NSError * _Nullable) NS_SWIFT_NAME(Purchases.PaymentDiscountBlock);

// [p presentCodeRedemptionSheet]; ///TODO: iOS ONLY, TEST FOR THIS API BY LOOKING UP SELECTOR
// TODO: iOS ONLY, TEST FOR THIS API BY LOOKING UP SELECTOR
// [p presentCodeRedemptionSheet];
RCPurchases *p = [RCPurchases configureWithAPIKey:@""];

[RCPurchases setLogHandler:^(RCLogLevel l, NSString *i) {}];
Expand Down Expand Up @@ -67,7 +70,7 @@ + (void)allTheThings {
SKProductDiscount *skpd = [[SKProductDiscount alloc] init];
SKPaymentDiscount *skmd = [[SKPaymentDiscount alloc] init];

RCPackage *pack = [[RCPackage alloc] init];
RCPackage *pack = [[RCPackage alloc] initWithIdentifier:@"" packageType:RCPackageTypeCustom product:skp offeringIdentifier:@""];
[RCPurchases configureWithAPIKey:@"" appUserID:@""];
[RCPurchases configureWithAPIKey:@"" appUserID:@"" observerMode:false];
[RCPurchases configureWithAPIKey:@"" appUserID:@"" observerMode:false userDefaults:nil];
Expand Down Expand Up @@ -115,6 +118,4 @@ + (void)allTheThings {
[p.delegate purchases:p shouldPurchasePromoProduct:skp defermentBlock:^(RCPurchaseCompletedBlock makeDeferredPurchase) {}];
}



@end
34 changes: 26 additions & 8 deletions Purchases.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
2D8E9D482523747D00AFEE11 /* NSDictionaryExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DD269162522A20A006AC4BC /* NSDictionaryExtensionsTests.swift */; };
2D8E9D54252374A600AFEE11 /* NSDictionary+RCExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8E9D52252374A600AFEE11 /* NSDictionary+RCExtensions.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D8E9D55252374A600AFEE11 /* NSDictionary+RCExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D8E9D53252374A600AFEE11 /* NSDictionary+RCExtensions.m */; };
2DA600382666D8DB00B9E79E /* RCLoggerBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DA600362666D8DB00B9E79E /* RCLoggerBridge.h */; settings = {ATTRIBUTES = (Private, ); }; };
2DA600392666D8DB00B9E79E /* RCLoggerBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DA600372666D8DB00B9E79E /* RCLoggerBridge.m */; };
2DAF814E25B24243002C621E /* RCIdentityManager+Protected.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DAF814D25B24243002C621E /* RCIdentityManager+Protected.h */; settings = {ATTRIBUTES = (Private, ); }; };
2DC19195255F36D10039389A /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC19194255F36D10039389A /* Logger.swift */; };
2DC5621F24EC63430031F69B /* PurchasesCoreSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2DC5621624EC63420031F69B /* PurchasesCoreSwift.framework */; };
Expand Down Expand Up @@ -246,6 +244,7 @@
B387F47A2683FDEA0028701F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B387F46D2683FDAC0028701F /* main.m */; };
B387F47B2683FDEA0028701F /* RevenueCatAPI.h in Sources */ = {isa = PBXBuildFile; fileRef = B387F46C2683FDAC0028701F /* RevenueCatAPI.h */; };
B387F47C2683FDEA0028701F /* RevenueCatAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = B387F46E2683FDAC0028701F /* RevenueCatAPI.m */; };
B3D3C47026856AFF00CB3C21 /* APITester.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D3C46F26856AFF00CB3C21 /* APITester.swift */; };
B3D5CFBD267282630056FA67 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = B3D5CFBC267282630056FA67 /* Nimble */; };
B3D5CFC0267282760056FA67 /* OHHTTPStubsSwift in Frameworks */ = {isa = PBXBuildFile; productRef = B3D5CFBF267282760056FA67 /* OHHTTPStubsSwift */; };
B3D5CFC2267282760056FA67 /* OHHTTPStubs in Frameworks */ = {isa = PBXBuildFile; productRef = B3D5CFC1267282760056FA67 /* OHHTTPStubs */; };
Expand Down Expand Up @@ -337,8 +336,6 @@
2D8F622224D30F9D00F993AA /* ReceiptParsingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptParsingError.swift; sourceTree = "<group>"; };
2D97458E24BDFCEF006245E9 /* IntroEligibilityCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntroEligibilityCalculator.swift; sourceTree = "<group>"; };
2DA0068E24E2E515002C59D3 /* MockIntroEligibilityCalculator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockIntroEligibilityCalculator.swift; sourceTree = "<group>"; };
2DA600362666D8DB00B9E79E /* RCLoggerBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCLoggerBridge.h; sourceTree = "<group>"; };
2DA600372666D8DB00B9E79E /* RCLoggerBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCLoggerBridge.m; sourceTree = "<group>"; };
2DAF814D25B24243002C621E /* RCIdentityManager+Protected.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCIdentityManager+Protected.h"; sourceTree = "<group>"; };
2DC19194255F36D10039389A /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
2DC5621624EC63420031F69B /* PurchasesCoreSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PurchasesCoreSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -575,6 +572,8 @@
B387F46E2683FDAC0028701F /* RevenueCatAPI.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RevenueCatAPI.m; sourceTree = "<group>"; };
B387F4732683FDDB0028701F /* APITester */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = APITester; sourceTree = BUILT_PRODUCTS_DIR; };
B387F4752683FDDB0028701F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
B3D3C46E26856AFE00CB3C21 /* APITester-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "APITester-Bridging-Header.h"; sourceTree = "<group>"; };
B3D3C46F26856AFF00CB3C21 /* APITester.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APITester.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -686,8 +685,6 @@
2D4C02E52669801D0038F877 /* Logging */ = {
isa = PBXGroup;
children = (
2DA600362666D8DB00B9E79E /* RCLoggerBridge.h */,
2DA600372666D8DB00B9E79E /* RCLoggerBridge.m */,
37E35EB9B60477A7AD2C2EB5 /* RCLogUtils.h */,
);
path = Logging;
Expand Down Expand Up @@ -1320,6 +1317,8 @@
B387F46D2683FDAC0028701F /* main.m */,
B387F46C2683FDAC0028701F /* RevenueCatAPI.h */,
B387F46E2683FDAC0028701F /* RevenueCatAPI.m */,
B3D3C46F26856AFF00CB3C21 /* APITester.swift */,
B3D3C46E26856AFE00CB3C21 /* APITester-Bridging-Header.h */,
);
path = PublicSDKAPITester;
sourceTree = "<group>";
Expand Down Expand Up @@ -1377,7 +1376,6 @@
37E3585A687FF4D7B69C554C /* RCDateProvider.h in Headers */,
37E354159288DE3D23212382 /* RCCrossPlatformSupport.h in Headers */,
37E35E9CEC36E93AF682D012 /* RCPromotionalOffer+Protected.h in Headers */,
2DA600382666D8DB00B9E79E /* RCLoggerBridge.h in Headers */,
37E352E86A182E92130B823C /* RCIntroEligibility+Protected.h in Headers */,
37E35C5A53AC7CF63B240FEC /* RCEntitlementInfos+Protected.h in Headers */,
37E3575B0FFDD90D01861D81 /* RCPurchasesErrorUtils+Protected.h in Headers */,
Expand Down Expand Up @@ -1597,6 +1595,7 @@
};
B387F4722683FDDB0028701F = {
CreatedOnToolsVersion = 12.5.1;
LastSwiftMigration = 1250;
};
};
};
Expand Down Expand Up @@ -1817,7 +1816,6 @@
37E358DB4F4016AC297D6B00 /* RCOfferingsFactory.m in Sources */,
37E35DD8BE40E352311AC2C1 /* RCPromotionalOffer.m in Sources */,
37E358250B07BF2DA06EA27B /* RCReceiptFetcher.m in Sources */,
2DA600392666D8DB00B9E79E /* RCLoggerBridge.m in Sources */,
37E35BDDC331C3A5FF72CFFF /* RCStoreKitRequestFetcher.m in Sources */,
37E35A299524507A480956D5 /* RCStoreKitWrapper.m in Sources */,
37E35A7ED3312F10B80FFE2B /* RCDeviceCache.m in Sources */,
Expand Down Expand Up @@ -1907,6 +1905,7 @@
B387F47A2683FDEA0028701F /* main.m in Sources */,
B387F47B2683FDEA0028701F /* RevenueCatAPI.h in Sources */,
B387F47C2683FDEA0028701F /* RevenueCatAPI.m in Sources */,
B3D3C47026856AFF00CB3C21 /* APITester.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2420,29 +2419,48 @@
B387F4782683FDDB0028701F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO;
CODE_SIGN_STYLE = Automatic;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift";
MACOSX_DEPLOYMENT_TARGET = 11.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "PublicSDKAPITester/APITester-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
B387F4792683FDDB0028701F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO;
CODE_SIGN_STYLE = Automatic;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift";
MACOSX_DEPLOYMENT_TARGET = 11.3;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "PublicSDKAPITester/APITester-Bridging-Header.h";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
33 changes: 0 additions & 33 deletions Purchases/Logging/RCLoggerBridge.h

This file was deleted.

51 changes: 0 additions & 51 deletions Purchases/Logging/RCLoggerBridge.m

This file was deleted.

7 changes: 3 additions & 4 deletions Purchases/Public/RCPurchases.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#import "RCIntroEligibility+Protected.h"
#import "RCReceiptRefreshPolicy.h"
#import "RCPurchaserInfoManager.h"
#import "RCLoggerBridge.h"
@import PurchasesCoreSwift;


Expand Down Expand Up @@ -103,15 +102,15 @@ + (BOOL)debugLogsEnabled {
}

+ (void)setLogHandler:(void(^)(RCLogLevel, NSString * _Nonnull))logHandler {
[RCLoggerBridge setLogHandler:logHandler];
RCLog.logHandler = logHandler;
}

+ (RCLogLevel)logLevel {
return RCLoggerBridge.logLevel;
return RCLog.logLevel;
}

+ (void)setLogLevel:(RCLogLevel)logLevel {
RCLoggerBridge.logLevel = logLevel;
RCLog.logLevel = logLevel;
}

+ (NSURL *)proxyURL {
Expand Down
3 changes: 1 addition & 2 deletions PurchasesCoreSwift/Logging/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import Foundation

// NOTE: this must exactly match the enum in RCLogging.h
@objc(RCInternalLogLevel) public enum LogLevel: Int {
@objc(RCLogLevel) public enum LogLevel: Int {
case debug, info, warn, error

func description() -> String {
Expand Down

0 comments on commit 49acaa2

Please sign in to comment.