Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RC API key for local development from local.xcconfig #4795

Merged
merged 6 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Local.xcconfig.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@
// as well as by Package.swift.
// ======

// Uncomment to enable the PAYWALL_COMPONENTS flag.
// SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) PAYWALL_COMPONENTS
// Add new compiler flags like this:
// SWIFT_ACTIVE_COMPILATION_CONDITIONS = $(inherited) NEW_FLAG

// Set your RevenueCat API key for local development here:
// REVENUECAT_API_KEY = your-api-key

// Set your your RevenueCat Proxy URL for local development here:
// REVENUECAT_PROXY_URL = your-revenuecat-proxy-url
2 changes: 0 additions & 2 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,6 @@
2DD5003F2C519EB4009C19B7 /* ci_pre_xcodebuild.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ci_pre_xcodebuild.sh; sourceTree = "<group>"; };
2DD500412C519EB4009C19B7 /* ConfigItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigItem.swift; sourceTree = "<group>"; };
2DD500422C519EB4009C19B7 /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
2DD500432C519EB4009C19B7 /* LocalConfigItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalConfigItems.swift; sourceTree = "<group>"; };
2DD500442C519EB4009C19B7 /* SamplePaywalls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SamplePaywalls.swift; sourceTree = "<group>"; };
2DD500462C519EB4009C19B7 /* ApplicationData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationData.swift; sourceTree = "<group>"; };
2DD500472C519EB4009C19B7 /* ApplicationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3069,7 +3068,6 @@
children = (
2DD500412C519EB4009C19B7 /* ConfigItem.swift */,
2DD500422C519EB4009C19B7 /* Configuration.swift */,
2DD500432C519EB4009C19B7 /* LocalConfigItems.swift */,
2DD500442C519EB4009C19B7 /* SamplePaywalls.swift */,
);
path = Config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
88BEB9262BF537F200A3D05F /* ConfigItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88BEB9222BF537F200A3D05F /* ConfigItem.swift */; };
88BEB9272BF537F200A3D05F /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88BEB9232BF537F200A3D05F /* Configuration.swift */; };
88BEB9282BF537F200A3D05F /* SamplePaywalls.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88BEB9242BF537F200A3D05F /* SamplePaywalls.swift */; };
88BEB9292BF537F200A3D05F /* LocalConfigItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88BEB9252BF537F200A3D05F /* LocalConfigItems.swift */; };
88DFC12E2BC7335200273B6D /* ApplicationData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88DFC12D2BC7335200273B6D /* ApplicationData.swift */; };
88DFC1322BC7385B00273B6D /* AuthenticationActor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88DFC1302BC7385A00273B6D /* AuthenticationActor.swift */; };
88DFC1332BC7385B00273B6D /* ApplicationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88DFC1312BC7385B00273B6D /* ApplicationManager.swift */; };
Expand Down Expand Up @@ -128,7 +127,6 @@
88BEB9222BF537F200A3D05F /* ConfigItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConfigItem.swift; path = Config/ConfigItem.swift; sourceTree = "<group>"; };
88BEB9232BF537F200A3D05F /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Configuration.swift; path = Config/Configuration.swift; sourceTree = "<group>"; };
88BEB9242BF537F200A3D05F /* SamplePaywalls.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SamplePaywalls.swift; path = Config/SamplePaywalls.swift; sourceTree = "<group>"; };
88BEB9252BF537F200A3D05F /* LocalConfigItems.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LocalConfigItems.swift; path = Config/LocalConfigItems.swift; sourceTree = "<group>"; };
88DFC12D2BC7335200273B6D /* ApplicationData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationData.swift; sourceTree = "<group>"; };
88DFC1302BC7385A00273B6D /* AuthenticationActor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthenticationActor.swift; sourceTree = "<group>"; };
88DFC1312BC7385B00273B6D /* ApplicationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApplicationManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -256,7 +254,6 @@
children = (
88BEB9222BF537F200A3D05F /* ConfigItem.swift */,
88BEB9232BF537F200A3D05F /* Configuration.swift */,
88BEB9252BF537F200A3D05F /* LocalConfigItems.swift */,
88BEB9242BF537F200A3D05F /* SamplePaywalls.swift */,
880B2AF12BEC2D62006B9393 /* Preprocessor.sh */,
880B2AF32BEC35AA006B9393 /* Postprocessor.sh */,
Expand Down Expand Up @@ -504,7 +501,6 @@
88BEB9282BF537F200A3D05F /* SamplePaywalls.swift in Sources */,
88DFC18D2BCF3AD100273B6D /* AsyncButton.swift in Sources */,
88DFC18E2BCF3AD100273B6D /* ErrorDisplay.swift in Sources */,
88BEB9292BF537F200A3D05F /* LocalConfigItems.swift in Sources */,
88A52D132C8A09B900075D09 /* PaywallComponentCollectionExtensions.swift in Sources */,
88DFC1882BCF3AB700273B6D /* LoginScreen.swift in Sources */,
88DFC1892BCF3AB700273B6D /* LoginWall.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

import Foundation

protocol AvailableConfigItems {
static var apiKey: String { get }
static var proxyURL: String? { get }
}

// CI system adds keys here
extension AvailableConfigItems {
static var apiKey: String { "" }
static var proxyURL: String? { nil }
}

struct ConfigItem: AvailableConfigItems {
// DO NOT MODIFY THIS FILE.
// CI system adds the API key here.
Comment on lines +10 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about removing this file and making the CI script create a Local.xcconfig file instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this file is still needed for the PaywallsTester app. I mean, not needed per se, but it's good to have a centralized place where we get the necessary variables from the info.plist.

Regarding having the CI script create a Local.xcconfig, I think that could totally work, yes. I'll open a separate PR for the CI changes related to this one 👍

struct ConfigItem {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
struct ConfigItem {
enum ConfigItem {

/*
To add your own API key for local development, add it in your local.xcconfig file like this:
REVENUECAT_API_KEY = your-api-key
*/
static var apiKey: String { Bundle.main.object(forInfoDictionaryKey: "REVENUECAT_API_KEY") as? String ?? "" }

/*
To add your own proxyURL for local development, add it in your local.xcconfig file like this:
REVENUECAT_PROXY_URL = your-api-key
*/
static var proxyURL: String? { Bundle.main.object(forInfoDictionaryKey: "REVENUECAT_PROXY_URL") as? String }
}

This file was deleted.

4 changes: 4 additions & 0 deletions Tests/TestingApps/PaywallsTester/PaywallsTester/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>REVENUECAT_API_KEY</key>
<string>$(REVENUECAT_API_KEY)</string>
<key>REVENUECAT_PROXY_URL</key>
<string>$(REVENUECAT_PROXY_URL)</string>
</dict>
</plist>
5 changes: 4 additions & 1 deletion Tests/TestingApps/PurchaseTesterSwiftUI/Core/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public struct Constants {
/*
The API key for your app from the RevenueCat dashboard: https://app.revenuecat.com
This is the default used by `ConfigurationView`

To add your own API key for local development, add it in your local.xcconfig file like this:
REVENUECAT_API_KEY = your-api-key
*/
public static let apiKey = "REVENUECAT_API_KEY"
public static var apiKey: String { Bundle.main.object(forInfoDictionaryKey: "REVENUECAT_API_KEY") as? String ?? "" }

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>REVENUECAT_API_KEY</key>
<string>$(REVENUECAT_API_KEY)</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
57ED6A83290891AF009580C6 /* ConfiguredPurchases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfiguredPurchases.swift; sourceTree = "<group>"; };
57ED6A85290893B6009580C6 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
57FA0F7C2908503B00E9EA1B /* PurchaseTester.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PurchaseTester.entitlements; sourceTree = "<group>"; };
757594DC2D64AB8C001B06F5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
773C13482CB58A6100219E42 /* Global.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Global.xcconfig; path = ../../../Global.xcconfig; sourceTree = "<group>"; };
773C13492CB58A7400219E42 /* Local.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Local.xcconfig; path = ../../../Local.xcconfig; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -298,6 +299,7 @@
578DAA0A2947DD21001700FD /* PurchaseTesterWatchOS */ = {
isa = PBXGroup;
children = (
757594DC2D64AB8C001B06F5 /* Info.plist */,
578DAA0B2947DD21001700FD /* PurchaseTesterWatchApp.swift */,
578DAA0D2947DD21001700FD /* ContentView.swift */,
578DAA0F2947DD21001700FD /* Assets.xcassets */,
Expand Down Expand Up @@ -805,6 +807,7 @@
DEVELOPMENT_TEAM = 8SXR2327BM;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = PurchaseTesterWatchOS/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = PurchaseTesterWatchOS;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.revenuecat.sampleapp;
Expand Down Expand Up @@ -833,6 +836,7 @@
CURRENT_PROJECT_VERSION = 1;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = PurchaseTesterWatchOS/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = PurchaseTesterWatchOS;
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = com.revenuecat.sampleapp;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>REVENUECAT_API_KEY</key>
<string>$(REVENUECAT_API_KEY)</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import RevenueCat
struct ConfigurationView: View {

struct Data: Equatable, Codable {
var apiKey: String = Constants.apiKey.replacingOccurrences(of: "REVENUECAT_API_KEY",
with: "")
var apiKey: String = Constants.apiKey
var proxy: String = ""
var storeKit2Enabled: Bool = true
var verificationMode: Configuration.EntitlementVerificationMode = .disabled
Expand Down
2 changes: 1 addition & 1 deletion scripts/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ verify_no_included_apikeys() {
"${SCRIPT_DIR}/../Examples/MagicWeather/MagicWeather/Constants.swift"
"${SCRIPT_DIR}/../Examples/MagicWeatherSwiftUI/Shared/Constants.swift"
"${SCRIPT_DIR}/../Tests/TestingApps/PurchaseTesterSwiftUI/Core/Constants.swift"
"${SCRIPT_DIR}/../Tests/TestingApps/PaywallsTester/PaywallsTester/Config/LocalConfigItems.swift"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not get rid of all of these files, so we can get rid of the entire verify_no_included_apikeys() check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I see the utility of having then in the sense that someone might forget about the local.xcconfig file thing and perhaps wants to do a quick change of the API key and they do it in the code directly. So it does not harm. That said, by that argument, I'd need to add the ConfigItem.swift file to it 😄

"${SCRIPT_DIR}/../Tests/TestingApps/PaywallsTester/PaywallsTester/Config/ConfigItem.swift"
)
FILES_STAGED=$(git diff --cached --name-only)
PATTERN="\"REVENUECAT_API_KEY\""
Expand Down