ios开发中订阅的申请流程

1. 登录App store connect 平台 https://appstoreconnect.apple.com/business

        填写银行卡收款信息,填写传真, 确保是激活状态

        

2. 添加订阅或内购(这里以订阅为例)

3. 创建Group,每个group中添加订阅的年,月

        添加的时候需要添加名称,产品id(一般就是自己的bundleid在添加对应monthly,或yearly)

        之后必须保证订阅的年或月中填写信息完成,状态变成preparing for review 状态就是ok的,waiting for review是提交审核后的状态

需要填写的信息如下:

4. 在App 的版本信息页面选择订阅信息

 5. 代码集成StoreKit或三方的SwiftyStoreKit(https://github.com/bizz84/SwiftyStoreKit)

//
//  AdsSubscriptionManager.swift
//  RecRoad
//
//  Created by Macle on 8/11/2024.
//

import UIKit
import SwiftyStoreKit
import StoreKit


final class AdsSubscriptionManager: NSObject {
    static var myShared = AdsSubscriptionManager()
    
    var isSubcriptedUser = false
    var productIDList: [SKProduct] = []
    
    func showSubscriptionViewController() {
        let subscriptionVC = AdsSubscriptionViewController()
        subscriptionVC.isFirstShow = false
        subscriptionVC.modalTransitionStyle = .coverVertical
        subscriptionVC.modalPresentationStyle = .overFullScreen
        AppDevice.getStackTopViewController().present(subscriptionVC, animated: true)
    }
    
    // boldly订阅的产品列表
    func getSubscriptionList(completeHandle:@escaping () -> Void) {
        SwiftyStoreKit.retrieveProductsInfo([ADS_SUBSCRIPTION_MONTHLY, ADS_SUBSCRIPTION_YEARLY]) { [weak self] myResults in
            guard let self = self else { return }
            
            self.productIDList.removeAll()
            self.productIDList.append(contentsOf: myResults.retrievedProducts.filter { $0.productIdentifier == ADS_SUBSCRIPTION_MONTHLY })
            self.productIDList.append(contentsOf: myResults.retrievedProducts.filter { $0.productIdentifier == ADS_SUBSCRIPTION_YEARLY })
            if let invalidProdeuctId = myResults.invalidProductIDs.first {
                print("Invalid product identifier: \(invalidProdeuctId)")
            } else {
                print("Error: \(String(describing: myResults.error))")
            }
            completeHandle()
        }
    }
    
    // 根据产品id去订阅信息
    func subscriptProduct(productID: String, completeHandle:@escaping (_ isSuccess: Bool) -> Void) {
        SwiftyStoreKit.purchaseProduct(productID, quantity: 1, atomically: true) { myResult in
            switch myResult {
            case .success(purchase: let purchase):
                print("Purchase Success: \(purchase.productId)")
                
                // downloads
                let download = purchase.transaction.downloads
                if !download.isEmpty {
                    SwiftyStoreKit.start(download)
                }
                completeHandle(true)
            case .deferred(purchase: let purchase):
                print("deferred: \(purchase.productId)")
                completeHandle(false)
            case .error(error: let purchase):
                completeHandle(false)
                print(purchase.code)
            }
        }
    }
    
    // 账号恢复
    func restoreAdsUserStatus(completeHandle:@escaping (_ isSuccess: Bool) -> Void) {
        SwiftyStoreKit.restorePurchases(atomically: true) { myResult in
            if myResult.restoreFailedPurchases.count > 0 {
                print("Rstore Failed: \(myResult.restoreFailedPurchases)")
                completeHandle(false)
            } else if myResult.restoredPurchases.count > 0 {
                print("Restore Success: \(myResult.restoredPurchases)")
                self.isSubcriptedUser = true
                completeHandle(true)
            } else {
                print("Nothing to Restore")
                completeHandle(false)
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Macle_Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值