如何解决如何在 iOS 11.2 以下获得应用内购买订阅期?
我是应用内购买的新手。如何在 iOS 11.2 以下获得订阅期?正如我所见,它可以从 iOS 11.2 的 SKProduct 类中获得。 我的代码是这样的:
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
}
}
我还想在 iOS 11.2 以下提供 durationNumberString 和 durationUnitString 值。
解决方法
我找到了解决方案。在 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
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。