如何检查客户是否可以使用 StoreKit 进行应用内购买?
How do I check if a customer can make in-app purchases using StoreKit?
我想在客户禁用应用内购买时隐藏应用内购买列表(这可能是由于家长限制)。
到目前为止我有什么(在iOS 15上使用Swift 5 & SwiftUI) ⤵︎
// store.products is a Published property that contains an array of
// fetched StoreKit.Products.
if let products = store.products {
// This is the list of in-app purchases. InAppPurchase is a custom view.
ForEach(products) { product in
InAppPurchase(product)
}
}
我该怎么做?
iOS 15 +
有一个简单的 bool 检查可以用来查看是否启用了付款 ⤵︎
AppStore.canMakePayments // Is a bool property
iOS14岁及以下
正如@el-tomato 所说,除了兼容性之外,下面的内容与 AppStore.canMakePayments
几乎没有区别。对于旧设备,请使用此 ⤵︎
SKPaymentQueue.canMakePayments() // Returns a bool
使用中⤵︎
// iOS 15 +
if AppStore.canMakePayments, let products = store.products {
ForEach(products) { product in
InAppPurchase(product)
}
}
// iOS 14 and below
if SKPaymentQueue.canMakePayments(), let products = store.products {
ForEach(products) { product in
InAppPurchase(product)
}
}
我想在客户禁用应用内购买时隐藏应用内购买列表(这可能是由于家长限制)。
到目前为止我有什么(在iOS 15上使用Swift 5 & SwiftUI) ⤵︎
// store.products is a Published property that contains an array of
// fetched StoreKit.Products.
if let products = store.products {
// This is the list of in-app purchases. InAppPurchase is a custom view.
ForEach(products) { product in
InAppPurchase(product)
}
}
我该怎么做?
iOS 15 +
有一个简单的 bool 检查可以用来查看是否启用了付款 ⤵︎
AppStore.canMakePayments // Is a bool property
iOS14岁及以下
正如@el-tomato 所说,除了兼容性之外,下面的内容与 AppStore.canMakePayments
几乎没有区别。对于旧设备,请使用此 ⤵︎
SKPaymentQueue.canMakePayments() // Returns a bool
使用中⤵︎
// iOS 15 +
if AppStore.canMakePayments, let products = store.products {
ForEach(products) { product in
InAppPurchase(product)
}
}
// iOS 14 and below
if SKPaymentQueue.canMakePayments(), let products = store.products {
ForEach(products) { product in
InAppPurchase(product)
}
}