mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
Fixes https://community.revenuecat.com/sdks-51/objective-c-how-to-access-rcstorefront-1647?postid=5154#post5154 `RCStoreFront` does have a `currentStorefront` property which supports StoreKit 1 and StoreKit 2, but due to the fact that the SK2 way of obtaining the current storefront is `async`, this property is only `async`, which means that it indeed isn’t available on Objective-C. This adds a way to be able to access the current storefront from Objective-C.
49 lines
1.7 KiB
Swift
49 lines
1.7 KiB
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// StorefrontTests.swift
|
|
//
|
|
// Created by Nacho Soto on 4/13/22.
|
|
|
|
import Nimble
|
|
@testable import RevenueCat
|
|
import StoreKit
|
|
import XCTest
|
|
|
|
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, macCatalyst 13.1, *)
|
|
class StorefrontTests: StoreKitConfigTestCase {
|
|
|
|
@available(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0, *)
|
|
func testCurrentStorefrontSK2() async throws {
|
|
try AvailabilityChecks.iOS15APIAvailableOrSkipTest()
|
|
|
|
let expectedStorefront = try await XCTAsyncUnwrap(await StoreKit.Storefront.current)
|
|
let currentStorefront = try await XCTAsyncUnwrap(await Storefront.currentStorefront)
|
|
|
|
expect(currentStorefront.identifier) == expectedStorefront.id
|
|
expect(currentStorefront.countryCode) == expectedStorefront.countryCode
|
|
|
|
}
|
|
|
|
func testCurrentStorefrontSK1() async throws {
|
|
try AvailabilityChecks.iOS13APIAvailableOrSkipTest()
|
|
|
|
if #unavailable(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0) {
|
|
let expectedStorefront = try XCTUnwrap(SKPaymentQueue.default().storefront)
|
|
let currentStorefront = try await XCTAsyncUnwrap(await Storefront.currentStorefront)
|
|
|
|
expect(currentStorefront.identifier) == expectedStorefront.identifier
|
|
expect(currentStorefront.countryCode) == expectedStorefront.countryCode
|
|
} else {
|
|
throw XCTSkip("This test is for pre-iOS 15 APIs")
|
|
}
|
|
}
|
|
|
|
}
|