I'm looking at setting up In App Purchases for an iPhone app. I'm planning on using the new auto-renewable subscription type. However, I want to offer multiple durations for a particular subscription, but can't see how I can retrieve the duration from the SKProduct that is returned in the SKProductsResponse.products array.
我正在寻找为iPhone应用程序设置In App Purchases。我打算使用新的自动更新订阅类型。但是,我想为特定订阅提供多个持续时间,但无法看到我如何从SKProductsResponse.products数组中返回的SKProduct中检索持续时间。
The SKProduct object has price, localizedTitle and localizedDescription. However, if you set up a subscription family with multiple durations the title/description are set once for the family so you cannot include the duration, and the docs explicitly say don't include the duration in the title/description. However, can't see any other field where I can retrieve the duration for displaying in my custom in app store. Either I'm missing something or it isn't going to be available until 4.3?
SKProduct对象具有price,localizedTitle和localizedDescription。但是,如果您设置具有多个持续时间的订阅系列,则为系列设置一次标题/说明,以便您不能包括持续时间,并且文档明确表示不在标题/说明中包含持续时间。但是,看不到任何其他字段,我可以检索在我的自定义应用商店中显示的持续时间。我要么缺少某些东西,要么在4.3之前无法使用?
Pointers greatly appreciated!
指针非常感谢!
3 个解决方案
#1
10
You need to have some mapping product_id => length
somewhere, either in your app or retrived from your app's backend.
你需要在某个地方有一些map_id => length的映射,要么在你的应用程序中,要么从应用程序的后端重新获得。
#2
10
You can use a specific productIdentifier for each duration (in the code below the productIdentifier for a 1 month subscription is "com.domainname.myapp.sub1month" and for a 7 day duration it is "com.domainname.myapp.sub7day") and search for that in the paymentQueue:
您可以为每个持续时间使用特定的productIdentifier(在productIdentifier下面的代码中,为期1个月的订阅是“com.domainname.myapp.sub1month”,对于7天的持续时间,它是“com.domainname.myapp.sub7day”)和在paymentQueue中搜索:
-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
switch (transaction.transactionState){
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:
if([transaction.payment.productIdentifier isEqualToString:@"com.domainname.myapp.sub1month"]{
newSubscriptionEndDate=[transaction.transactionDate timeIntervalSinceReferenceDate]+3600*24*31;
}
if([transaction.payment.productIdentifier isEqualToString:@"com.domainname.myapp.sub7day"] ){
newSubscriptionEndDate=[transaction.transactionDate timeIntervalSinceReferenceDate]+3600*24*7;
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
break;
#3
3
iOS 11.2 brings the subscriptionDuration
property to SKProduct
. I don't think there is a fallback for older iOS though.
iOS 11.2将subscriptionDuration属性带到SKProduct。我不认为旧的iOS会有回退。
https://developer.apple.com/documentation/storekit/skproduct/2936884-subscriptionperiod
https://developer.apple.com/documentation/storekit/skproduct/2936884-subscriptionperiod
#1
10
You need to have some mapping product_id => length
somewhere, either in your app or retrived from your app's backend.
你需要在某个地方有一些map_id => length的映射,要么在你的应用程序中,要么从应用程序的后端重新获得。
#2
10
You can use a specific productIdentifier for each duration (in the code below the productIdentifier for a 1 month subscription is "com.domainname.myapp.sub1month" and for a 7 day duration it is "com.domainname.myapp.sub7day") and search for that in the paymentQueue:
您可以为每个持续时间使用特定的productIdentifier(在productIdentifier下面的代码中,为期1个月的订阅是“com.domainname.myapp.sub1month”,对于7天的持续时间,它是“com.domainname.myapp.sub7day”)和在paymentQueue中搜索:
-(void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
switch (transaction.transactionState){
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:
if([transaction.payment.productIdentifier isEqualToString:@"com.domainname.myapp.sub1month"]{
newSubscriptionEndDate=[transaction.transactionDate timeIntervalSinceReferenceDate]+3600*24*31;
}
if([transaction.payment.productIdentifier isEqualToString:@"com.domainname.myapp.sub7day"] ){
newSubscriptionEndDate=[transaction.transactionDate timeIntervalSinceReferenceDate]+3600*24*7;
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
break;
#3
3
iOS 11.2 brings the subscriptionDuration
property to SKProduct
. I don't think there is a fallback for older iOS though.
iOS 11.2将subscriptionDuration属性带到SKProduct。我不认为旧的iOS会有回退。
https://developer.apple.com/documentation/storekit/skproduct/2936884-subscriptionperiod
https://developer.apple.com/documentation/storekit/skproduct/2936884-subscriptionperiod