【问题标题】:Determining if Xcode StoreKit Configuration file is being used确定是否正在使用 Xcode StoreKit 配置文件
【发布时间】:2021-07-25 00:30:51
【问题描述】:

Xcode 12 引入了StoreKit Configuration files,它非常适合在深入研究 App Store Connect、沙盒等之前测试基本的 StoreKit 功能。

有没有办法在运行时(甚至在编译时)确定方案的 StoreKit Configuration 值是设置为“无”还是某个文件?

【问题讨论】:

    标签: xcode in-app-purchase storekit xcode-scheme


    【解决方案1】:

    我只是想知道,因为我执行本地收据验证,我必须使用正确的证书:StoreKit 或 Apple 的根。

    解决方案非常简单:在您的 .storekit 文件中添加一个新产品,以检查您使用的是本地配置还是沙盒/App Store 配置。

    添加一个名为 using_store_kit_conf 的新产品 ID,然后将 ID 数组传递给同样包含此 ID 的 SKProductsRequest。 当您在委托中获得产品列表时,检查 using_store_kit_conf 产品是否存在以确定您是否正在使用 StoreKit 配置文件。

    如果您向用户列出所有产品,请记住过滤掉 using_store_kit_conf 产品。

    示例:

    static let premiumOneTime = "premium_one_time"
    static let usingStoreKitConfiguration = "using_store_kit_conf"
    static let productIds: Set<String> = [InAppPurchase.premiumOneTime, InAppPurchase.usingStoreKitConfiguration]
    private var products: [SKProduct] = []
    

    传递所有 ID:

    productsRequest = SKProductsRequest(productIdentifiers: InAppPurchase.productIds)
    

    代表:

    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        self.products = response.products
        print("InAppPurchase products: ", response.products)
    }
    

    检查是否使用 StoreKit 配置:

    var isUsingStoreKitConfiguration: Bool {
        products.contains(where: { product in product.productIdentifier == InAppPurchase.usingStoreKitConfiguration })
    }
    

    注意:这仅在您加载产品列表后有效,否则isUsingStoreKitConfiguration 将始终返回 false。

    【讨论】:

    • 虽然这不是我想要的解决方案,但它是我迄今为止遇到的最好的解决方案
    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 2013-10-19
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多