[英]How can I get in-app purchase subscription period below iOS 11.2?
I am new on in-app purchase.我是应用内购买的新手。 How can I get subscriptionPeriod below iOS 11.2?如何获得低于 iOS 11.2 的订阅时间? As I see it is available from iOS 11.2 in SKProduct class.正如我所见,它可从 SKProduct class 中的 iOS 11.2 获得。 My code is like this:我的代码是这样的:
var durationNumberString: String? {
if #available(iOS 11.2, *) {
guard let nu = product.subscriptionPeriod?.numberOfUnits else { return nil }
return "\(nu)"
} else {
return nil
}
}
var durationUnitString: String? {
if #available(iOS 11.2, *) {
guard let unit = product.subscriptionPeriod?.unit else { return nil }
switch unit {
case .day:
return "day"
case .week:
return "weak"
case .month:
return "month"
case .year:
return "year"
@unknown default:
return ""
}
} else {
return nil
}
}
I want to give durationNumberString and durationUnitString values below iOS 11.2 also.我也想给出低于 iOS 11.2 的durationNumberString和durationUnitString值。
I have found the solution.我找到了解决方案。 Before iOS 11.2 I can get durationNumberString and durationUnitString by hardcoding, using product identifier.在 iOS 11.2 之前,我可以使用产品标识符通过硬编码获得durationNumberString和durationUnitString 。
var durationNumberString: String? {
if #available(iOS 11.2, *) {
guard let nu = product.subscriptionPeriod?.numberOfUnits else { return nil }
return "\(nu)"
} else {
switch product.productIdentifier {
case "id_199_month":
return "1"
case "id_499_3month":
return "3"
case "id_2099_annual":
return "1"
default:
return nil
}
}
}
var durationUnitString: String? {
if #available(iOS 11.2, *) {
guard let unit = product.subscriptionPeriod?.unit else { return nil }
switch unit {
case .day:
return "day"
case .week:
return "weak"
case .month:
return "month"
case .year:
return "year"
@unknown default:
return ""
}
} else {
switch product.productIdentifier {
case "id_499_3month",
"id_199_month":
return "month"
case "id_2099_annual":
return "year"
default:
return nil
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.