【问题标题】:How can I get in-app purchase subscription period below iOS 11.2?如何获得 iOS 11.2 以下的应用内购买订阅期?
【发布时间】:2021-07-06 01:47:44
【问题描述】:

我是应用内购买的新手。如何获得低于 iOS 11.2 的订阅时间?正如我所见,它可以从 SKProduct 类的 iOS 11.2 中获得。 我的代码是这样的:

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 以下提供 durationNumberStringdurationUnitString 值。

【问题讨论】:

标签: ios swift in-app-purchase subscription duration


【解决方案1】:

我找到了解决方案。在 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
        }
    }
}

【讨论】:

    猜你喜欢
    • 2011-12-26
    • 2012-02-03
    • 2018-01-31
    • 1970-01-01
    • 2018-06-01
    • 2016-01-25
    • 2013-01-20
    • 2013-10-18
    • 2017-06-09
    相关资源
    最近更新 更多