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)
}
}
}
}