简体   繁体   English

如何获得低于 iOS 11.2 的应用内购买订阅期?

[英]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 的durationNumberStringdurationUnitString值。

I have found the solution.我找到了解决方案。 Before iOS 11.2 I can get durationNumberString and durationUnitString by hardcoding, using product identifier.在 iOS 11.2 之前,我可以使用产品标识符通过硬编码获得durationNumberStringdurationUnitString

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.

相关问题 iOS应用内购买订阅从SKProduct获得免费试用期 - iOS in-app purchase subscription get free trial period length from SKProduct 我如何从Apple的应用程序内购买中获得报酬? (iOS iTunesConnect) - How can I get paid for my app's in-app purchase from Apple? (iOS iTunesConnect) 我如何计算iOS中应用内购买的失败率 - How can i count the failure rate of in-app purchase in iOS 如何在 iOS 的应用内购买中获得活动产品的取消订阅? - How to get active product's cancel subscription in In-App Purchase in iOS? iOS:如果用户仍有资格免费试用应用内购买订阅,我该如何查明? - iOS: How do I find out, if a user is still eligible for a free trial of an in-app purchase subscription? 如果购买或订阅发生在 Web 应用程序中,是否不需要 iOS 应用程序内购买? - Is iOS in-app purchase not required if purchase or subscription happens in web app? 应用内购买订阅 - In-app Purchase Subscription 如何在Store Kit应用内购买中测试取消订阅? - How can I test a cancellation of subscription in Store Kit in-app purchase? iOS-我可以自定义Apple托管的应用内购买内容吗? - iOS - Can I customise in-app purchase content hosted with Apple? 如何查看应用内购买(自动续订)的购买状态? - How to check purchase status of In-App Purchase (Auto Renewing Subscription)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM