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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

visionOS: support for Xcode 15 beta 6 #2989

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 11 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -16,6 +16,14 @@ if shouldIncludeDocCPlugin {
dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"))
}

let swiftSettings: [SwiftSetting]

#if swift(>=5.9)
swiftSettings = [ .define("VISION_OS", .when(platforms: [.custom("visionOS")])) ]
#else
swiftSettings = []
#endif

let package = Package(
name: "RevenueCat",
platforms: [
Expand All @@ -39,7 +47,8 @@ let package = Package(
exclude: ["Info.plist", "LocalReceiptParsing/ReceiptParser-only-files"],
resources: [
.copy("../Sources/PrivacyInfo.xcprivacy")
]),
],
swiftSettings: swiftSettings),
.target(name: "RevenueCat_CustomEntitlementComputation",
path: "CustomEntitlementComputation",
exclude: ["Info.plist", "LocalReceiptParsing/ReceiptParser-only-files"],
Expand Down
4 changes: 4 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3937,6 +3937,8 @@
SUPPORTS_MACCATALYST = YES;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
"SWIFT_ACTIVE_COMPILATION_CONDITIONS[sdk=xros*]" = "$(inherited) VISION_OS";
"SWIFT_ACTIVE_COMPILATION_CONDITIONS[sdk=xrsimulator*]" = "$(inherited) VISION_OS";
TARGETED_DEVICE_FAMILY = "1,2,3,4,6,7";
};
name = Debug;
Expand Down Expand Up @@ -3974,6 +3976,8 @@
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos watchsimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES;
"SWIFT_ACTIVE_COMPILATION_CONDITIONS[sdk=xros*]" = "$(inherited) VISION_OS";
"SWIFT_ACTIVE_COMPILATION_CONDITIONS[sdk=xrsimulator*]" = "$(inherited) VISION_OS";
TARGETED_DEVICE_FAMILY = "1,2,3,4,6,7";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
//
// Created by Andr茅s Boedo on 8/20/21.

import Foundation
#if os(iOS)
#if os(iOS) || VISION_OS
import UIKit

extension UIApplication {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Misc/Concurrency/Purchases+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extension Purchases {

#endif

#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || VISION_OS

@available(iOS 13.0, macOS 10.15, *)
@available(watchOS, unavailable)
Expand Down
16 changes: 9 additions & 7 deletions Sources/Misc/SystemInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import Foundation

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || os(tvOS) || VISION_OS || targetEnvironment(macCatalyst)
import UIKit
#elseif os(watchOS)
import UIKit
Expand Down Expand Up @@ -142,7 +142,7 @@ class SystemInfo {
/// - Seealso: `isApplicationBackgrounded(completion:)`
@MainActor
var isApplicationBackgrounded: Bool {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || VISION_OS
return self.isApplicationBackgroundedIOSAndTVOS
#elseif os(macOS)
return false
Expand All @@ -161,7 +161,7 @@ class SystemInfo {
return ProcessInfo.processInfo.isOperatingSystemAtLeast(version)
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || VISION_OS
var sharedUIApplication: UIApplication? {
return Self.sharedUIApplication
}
Expand All @@ -179,7 +179,7 @@ class SystemInfo {

}

#if os(iOS)
#if os(iOS) || VISION_OS
extension SystemInfo {

@available(iOS 13.0, macCatalystApplicationExtension 13.1, *)
Expand Down Expand Up @@ -217,14 +217,16 @@ extension SystemInfo {
static let platformHeaderConstant = "tvOS"
#elseif os(macOS)
static let platformHeaderConstant = "macOS"
#elseif VISION_OS
static let platformHeaderConstant = "visionOS"
#endif

}

extension SystemInfo {

static var applicationWillEnterForegroundNotification: Notification.Name {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || VISION_OS
UIApplication.willEnterForegroundNotification
#elseif os(macOS)
NSApplication.willBecomeActiveNotification
Expand All @@ -234,7 +236,7 @@ extension SystemInfo {
}

static var applicationDidEnterBackgroundNotification: Notification.Name {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || VISION_OS
UIApplication.didEnterBackgroundNotification
#elseif os(macOS)
NSApplication.didResignActiveNotification
Expand All @@ -251,7 +253,7 @@ extension SystemInfo {

private extension SystemInfo {

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || VISION_OS

// iOS/tvOS App extensions can't access UIApplication.sharedApplication, and will fail to compile if any calls to
// it are made. There are no pre-processor macros available to check if the code is running in an app extension,
Expand Down
14 changes: 7 additions & 7 deletions Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -906,14 +906,14 @@ public extension Purchases {

#endif

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
@available(iOS 13.4, macCatalyst 13.4, *)
@objc func showPriceConsentIfNeeded() {
self.paymentQueueWrapper.paymentQueueWrapperType.showPriceConsentIfNeeded()
}
#endif

#if os(iOS)
#if os(iOS) || VISION_OS

@available(iOS 14.0, *)
@available(watchOS, unavailable)
Expand Down Expand Up @@ -951,7 +951,7 @@ public extension Purchases {

#endif

#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || VISION_OS

@available(watchOS, unavailable)
@available(tvOS, unavailable)
Expand All @@ -966,12 +966,12 @@ public extension Purchases {
@available(tvOS, unavailable)
@available(iOS 13.0, macOS 10.15, *)
func showManageSubscriptions() async throws {
return try await showManageSubscriptionsAsync()
return try await self.showManageSubscriptionsAsync()
}

#endif

#if os(iOS)
#if os(iOS) || VISION_OS

@available(iOS 15.0, *)
@available(macOS, unavailable)
Expand Down Expand Up @@ -1255,7 +1255,7 @@ extension Purchases: PurchasesOrchestratorDelegate {
self.delegate?.purchases?(self, readyForPromotedProduct: product, purchase: startPurchase)
}

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
@available(iOS 13.4, macCatalyst 13.4, *)
var shouldShowPriceConsent: Bool {
self.delegate?.shouldShowPriceConsent ?? true
Expand Down Expand Up @@ -1496,7 +1496,7 @@ private extension Purchases {
#if !ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION
(self as DeprecatedSearchAdsAttribution).postAppleSearchAddsAttributionCollectionIfNeeded()

#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || VISION_OS
if #available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *) {
self.attribution.postAdServicesTokenOncePerInstallIfNeeded()
}
Expand Down
18 changes: 6 additions & 12 deletions Sources/Purchasing/Purchases/PurchasesOrchestrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,9 @@ final class PurchasesOrchestrator {
_ product: SK2Product,
_ options: Set<Product.PurchaseOption>
) async throws -> Product.PurchaseResult {
// Note: this can be simplified as `#if swift(>=5.9) && os(xrOS)`
// once we drop support for Xcode 13.x
#if swift(>=5.9)
#if os(xrOS)
return try await product.purchase(confirmIn: try self.systemInfo.currentWindowScene,
options: options)
#else
return try await product.purchase(options: options)
#endif
#if VISION_OS
return try await product.purchase(confirmIn: try self.systemInfo.currentWindowScene,
options: options)
#else
return try await product.purchase(options: options)
#endif
Expand All @@ -541,7 +535,7 @@ final class PurchasesOrchestrator {
self.presentedOfferingIDsByProductID.modify { $0[productIdentifier] = identifier }
}

#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || VISION_OS

@available(watchOS, unavailable)
@available(tvOS, unavailable)
Expand All @@ -557,7 +551,7 @@ final class PurchasesOrchestrator {
}
#endif

#if os(iOS)
#if os(iOS) || VISION_OS

@available(iOS 15.0, *)
@available(macOS, unavailable)
Expand Down Expand Up @@ -695,7 +689,7 @@ extension PurchasesOrchestrator: StoreKit1WrapperDelegate {

extension PurchasesOrchestrator: PaymentQueueWrapperDelegate {

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
@available(iOS 13.4, macCatalyst 13.4, *)
var paymentQueueWrapperShouldShowPriceConsent: Bool {
return self.storeKit1WrapperShouldShowPriceConsent
Expand Down
10 changes: 5 additions & 5 deletions Sources/Purchasing/StoreKit1/PaymentQueueWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protocol PaymentQueueWrapperDelegate: AnyObject, Sendable {
shouldAddStorePayment payment: SKPayment,
for product: SK1Product) -> Bool

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
@available(iOS 13.4, macCatalyst 13.4, *)
var paymentQueueWrapperShouldShowPriceConsent: Bool { get }
#endif
Expand All @@ -33,7 +33,7 @@ protocol PaymentQueueWrapperType: AnyObject {

func finishTransaction(_ transaction: SKPaymentTransaction, completion: @escaping () -> Void)

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
@available(iOS 13.4, macCatalyst 13.4, *)
func showPriceConsentIfNeeded()
#endif
Expand Down Expand Up @@ -89,14 +89,14 @@ class PaymentQueueWrapper: NSObject, PaymentQueueWrapperType {
completion()
}

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
@available(iOS 13.4, macCatalyst 13.4, *)
func showPriceConsentIfNeeded() {
self.paymentQueue.showPriceConsentIfNeeded()
}
#endif

#if os(iOS) && !targetEnvironment(macCatalyst)
#if (os(iOS) && !targetEnvironment(macCatalyst)) || VISION_OS
@available(iOS 14.0, *)
func presentCodeRedemptionSheet() {
self.paymentQueue.presentCodeRedemptionSheetIfAvailable()
Expand All @@ -117,7 +117,7 @@ class PaymentQueueWrapper: NSObject, PaymentQueueWrapperType {

extension PaymentQueueWrapper: SKPaymentQueueDelegate {

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
@available(iOS 13.4, macCatalyst 13.4, *)
func paymentQueueShouldShowPriceConsent(_ paymentQueue: SKPaymentQueue) -> Bool {
return self.delegate?.paymentQueueWrapperShouldShowPriceConsent ?? true
Expand Down
4 changes: 2 additions & 2 deletions Sources/Purchasing/StoreKit1/StoreKit1Wrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ extension StoreKit1Wrapper: PaymentQueueWrapperType {
}
}

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
@available(iOS 13.4, macCatalyst 13.4, *)
func showPriceConsentIfNeeded() {
self.paymentQueue.showPriceConsentIfNeeded()
}
#endif

#if os(iOS) && !targetEnvironment(macCatalyst)
#if (os(iOS) && !targetEnvironment(macCatalyst)) || VISION_OS
@available(iOS 14.0, *)
func presentCodeRedemptionSheet() {
self.paymentQueue.presentCodeRedemptionSheetIfAvailable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
// Created by Madeline Beyl on 10/21/21.

#if os(iOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
import Foundation
import StoreKit
import UIKit
Expand Down
8 changes: 4 additions & 4 deletions Sources/Support/BeginRefundRequestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BeginRefundRequestHelper {
private let customerInfoManager: CustomerInfoManager
private let currentUserProvider: CurrentUserProvider

#if os(iOS)
#if os(iOS) || VISION_OS

private var _sk2Helper: Any?

Expand All @@ -49,7 +49,7 @@ class BeginRefundRequestHelper {
self.customerInfoManager = customerInfoManager
self.currentUserProvider = currentUserProvider

#if os(iOS)
#if os(iOS) || VISION_OS
if #available(iOS 15, *) {
self._sk2Helper = SK2BeginRefundRequestHelper()
} else {
Expand All @@ -58,7 +58,7 @@ class BeginRefundRequestHelper {
#endif
}

#if os(iOS)
#if os(iOS) || VISION_OS
/*
* Entry point for beginning the refund request. Handles getting the current windowScene and verifying the
* transaction before calling into `SK2BeginRefundRequestHelper`'s `initiateRefundRequest`.
Expand Down Expand Up @@ -103,7 +103,7 @@ extension BeginRefundRequestHelper: @unchecked Sendable {}

// MARK: - Private

#if os(iOS)
#if os(iOS) || VISION_OS
@available(iOS 15.0, *)
@available(macOS, unavailable)
@available(watchOS, unavailable)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Support/DebugUI/DebugContentViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
// Created by Nacho Soto on 5/30/23.

#if DEBUG && swift(>=5.8) && (os(iOS) || os(macOS))
#if DEBUG && swift(>=5.8) && (os(iOS) || os(macOS) || VISION_OS)

import StoreKit
import SwiftUI
Expand Down Expand Up @@ -293,7 +293,7 @@ private struct DebugOfferingView: View {
.foregroundStyle(.secondary)
.font(.subheadline)
}
#if !(swift(>=5.9) && os(xrOS))
#if !VISION_OS
.containerBackground(for: .subscriptionStoreFullHeight) {
Rectangle()
.edgesIgnoringSafeArea(.all)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Support/DebugUI/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
// Created by Nacho Soto on 5/30/23.

#if DEBUG && swift(>=5.8) && (os(iOS) || os(macOS))
#if DEBUG && swift(>=5.8) && (os(iOS) || os(macOS) || VISION_OS)

import SwiftUI

Expand Down Expand Up @@ -61,15 +61,15 @@ public extension View {
DebugSwiftUIRootView()
#if os(macOS)
.frame(width: 500, height: 600)
#elseif swift(>=5.9) && os(xrOS)
#elseif VISION_OS
.frame(width: 600, height: 700)
#endif
}
)
}

private var detents: Set<PresentationDetent> {
#if swift(>=5.9) && os(xrOS)
#if VISION_OS
return [.large]
#else
return [
Expand Down
Loading