1曙聂、為APP內的內容和服務提供內購方式
2颂翼、通過App Store-signed交易核實用戶的支付
3、驗證由廣告驅動的應用程序安裝
4、為第三方內容提供建議
5鸽素、請求應用程序的應用商店的評論和評級
6、在應用程序中顯示應用程序應用商店的消息
StoreKit概覽
**支付相關**
#import <StoreKit/SKDownload.h>
#import <StoreKit/SKError.h>
#import <StoreKit/SKPayment.h>
#import <StoreKit/SKPaymentDiscount.h>
#import <StoreKit/SKPaymentQueue.h>
#import <StoreKit/SKPaymentTransaction.h>
// 商品信息
#import <StoreKit/SKProduct.h>
// 商品折扣信息
#import <StoreKit/SKProductDiscount.h>
// 用于查詢APP在蘋果后臺配置的商品信息
#import <StoreKit/SKProductsRequest.h>
// App Store產品頁面上為每臺設備設置促銷的應用內購買的順序
// 詳見:https://developer.apple.com/app-store/promoting-in-app-purchases/
#import <StoreKit/SKProductStorePromotionController.h>
// 刷新票據結果(無用?)
#import <StoreKit/SKReceiptRefreshRequest.h>
// 抽象類,子類SKProductsRequest和SKReceiptRefreshRequest
#import <StoreKit/SKRequest.h>
**廣告網絡歸因**
#import <StoreKit/SKAdImpression.h>
#import <StoreKit/SKAdNetwork.h>
#import <StoreKit/SKArcadeService.h>
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
#import <StoreKit/SKANError.h>
#endif
**Apple Music**
// 用于協(xié)助用戶進行云服務設置 (例如 Apple Music 訂閱) 的視圖控制器街夭。
#import <StoreKit/SKCloudServiceController.h>
// 用于確定用戶音樂資料庫的當前功能的對象。
#import <StoreKit/SKCloudServiceSetupViewController.h>
**APP 評論和推薦**
// 用于控制請求用戶提供 App Store 評分和評論的流程的對象躏筏。
#import <StoreKit/SKStoreReviewController.h>
#import <StoreKit/SKStorefront.h>
// 提供可供用戶從 App Store 購買媒體的頁面的視圖控制器板丽。
#import <StoreKit/SKStoreProductViewController.h>
#import <StoreKit/StoreKitDefines.h>
// 用于顯示疊層的類,可供您用來推薦另一個 App 或輕 App 的相應完整 App趁尼。
#import <StoreKit/SKOverlay.h>
#import <StoreKit/SKOverlayConfiguration.h>
#import <StoreKit/SKOverlayTransitionContext.h>
SK升級埃碱,僅涉及支付相關流程,其他內容不作調整(上表的第一部分)
SKDownload(API_DEPRECATED)
SKError
支付錯誤酥泞,枚舉列表
// error codes for the SKErrorDomain
typedef NS_ENUM(NSInteger,SKErrorCode) {
SKErrorUnknown,
SKErrorClientInvalid, // client is not allowed to issue the request, etc.
SKErrorPaymentCancelled, // user cancelled the request, etc.
SKErrorPaymentInvalid, // purchase identifier was invalid, etc.
SKErrorPaymentNotAllowed, // this device is not allowed to make the payment
SKErrorStoreProductNotAvailable API_AVAILABLE(ios(3.0), macos(10.15), watchos(6.2)), // Product is not available in the current storefront
SKErrorCloudServicePermissionDenied API_AVAILABLE(ios(9.3), tvos(9.3), watchos(6.2), macos(11.0)), // user has not allowed access to cloud service information
SKErrorCloudServiceNetworkConnectionFailed API_AVAILABLE(ios(9.3), tvos(9.3), watchos(6.2), macos(11.0)), // the device could not connect to the nework
SKErrorCloudServiceRevoked API_AVAILABLE(ios(10.3), tvos(10.3), watchos(6.2), macos(11.0)), // user has revoked permission to use this cloud service
SKErrorPrivacyAcknowledgementRequired API_AVAILABLE(ios(12.2), tvos(12.2), macos(10.14.4), watchos(6.2)), // The user needs to acknowledge Apple's privacy policy
SKErrorUnauthorizedRequestData API_AVAILABLE(ios(12.2), macos(10.14.4), watchos(6.2)), // The app is attempting to use SKPayment's requestData property, but does not have the appropriate entitlement
SKErrorInvalidOfferIdentifier API_AVAILABLE(ios(12.2), macos(10.14.4), watchos(6.2)), // The specified subscription offer identifier is not valid
SKErrorInvalidSignature API_AVAILABLE(ios(12.2), macos(10.14.4), watchos(6.2)), // The cryptographic signature provided is not valid
SKErrorMissingOfferParams API_AVAILABLE(ios(12.2), macos(10.14.4), watchos(6.2)), // One or more parameters from SKPaymentDiscount is missing
SKErrorInvalidOfferPrice API_AVAILABLE(ios(12.2), macos(10.14.4), watchos(6.2)), // The price of the selected offer is not valid (e.g. lower than the current base subscription price)
SKErrorOverlayCancelled API_AVAILABLE(ios(12.2), macos(10.14.4), watchos(6.2)),
SKErrorOverlayInvalidConfiguration API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(macos, watchos) __TVOS_PROHIBITED,
SKErrorOverlayTimeout API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(macos, watchos) __TVOS_PROHIBITED,
SKErrorIneligibleForOffer API_AVAILABLE(ios(14.0), macos(11.0), watchos(7.0)), // User is not eligible for the subscription offer
SKErrorUnsupportedPlatform API_AVAILABLE(ios(14.0), macos(11.0), watchos(7.0)) __TVOS_PROHIBITED,
SKErrorOverlayPresentedInBackgroundScene API_AVAILABLE(ios(14.5)) API_UNAVAILABLE(macos, watchos) __TVOS_PROHIBITED // Client tried to present an SKOverlay in UIWindowScene not in the foreground
} API_AVAILABLE(ios(3.0), macos(10.7), watchos(6.2));
SKPayment
@interface SKPayment : NSObject <NSCopying, NSMutableCopying> {
+ (instancetype)paymentWithProduct:(SKProduct *)product;
// 在使用SKProductsRequest獲取可見的products后使用 +paymentWithProduct:
+ (id)paymentWithProductIdentifier:(NSString *)identifier
// 與appStroe對應的標識符, 必選參數
@property(nonatomic, copy, readonly) NSString *productIdentifier;
// 與商店對應的付款請求數據砚殿。可選
@property(nonatomic, copy, readonly, nullable) NSData *requestData;
// 默認1, 優(yōu)先級.
@property(nonatomic, readonly) NSInteger quantity;
// 使用者信息, 可選
@property(nonatomic, copy, readonly, nullable) NSString *applicationUsername;
// 在沙箱中強制執(zhí)行此付款的“購買請求”流程 (iOS8.3以上版本)
@property(nonatomic, readonly) BOOL simulatesAskToBuyInSandbox;
// 指定折扣的相關數據將適用于此付款芝囤∷蒲祝可選的。(iOS12.2 以上版本)
@property(nonatomic, copy, readonly, nullable) SKPaymentDiscount *paymentDiscount;
@end
@interface SKMutablePayment : SKPayment
@property(nonatomic, copy, readwrite, nullable) NSString *applicationUsername;
@property(nonatomic, copy, readwrite, nullable) SKPaymentDiscount *paymentDiscount;
@property(nonatomic, copy, readwrite) NSString *productIdentifier;
@property(nonatomic, readwrite) NSInteger quantity;
@property(nonatomic, copy, readwrite, nullable) NSData *requestData;
@property(nonatomic, readwrite) BOOL simulatesAskToBuyInSandbox;
@end
SKPaymentQueue
// 與服務器的支付隊列交互使用
@interface SKPaymentQueue : NSObject {
// 默認全局隊列
+ (instancetype)defaultQueue;
// 檢驗設備能否支持內購, YES: 能 默認是NO
+ (BOOL)canMakePayments;
// 異步事件, 添加一個支付事件到服務器隊列, 復制payment凡人,將SKPaymentTransaction添加到transaction事務數組中名党√纠可以多次添加相同的支付以創(chuàng)建多個事務挠轴。
- (void)addPayment:(SKPayment *)payment;
// 異步的。將當前用戶已完成的事務添加回要重新完成的隊列耳幢。將要求用戶進行身份驗證岸晦。觀察者將收到0個或更多-paymentQueue:updatedTransactions:,后面跟著任意一個(在部分成功的情況下睛藻,仍然可以交付一些事務启上。)
// -paymentQueueRestoreCompletedTransactionsFinished: on success
// -paymentQueue:restoreCompletedTransactionsFailedWithError: on failure.
- (void)restoreCompletedTransactions;
- (void)restoreCompletedTransactionsWithApplicationUsername:(nullable NSString *)username;
// 異步從隊列中刪除一個已結束的事務.
- (void)finishTransaction:(SKPaymentTransaction *)transaction;
// 異步下載商品信息
- (void)startDownloads:(NSArray<SKDownload *> *)downloads;
- (void)pauseDownloads:(NSArray<SKDownload *> *)downloads;
- (void)resumeDownloads:(NSArray<SKDownload *> *)downloads;
- (void)cancelDownloads:(NSArray<SKDownload *> *)downloads;
// 事務數組只有在隊列中有觀察者時才與服務器同步。這可能需要用戶進行身份驗證店印。
- (void)addTransactionObserver:(id <SKPaymentTransactionObserver>)observer;
- (void)removeTransactionObserver:(id <SKPaymentTransactionObserver>)observer;
// 未完成的事務數組. 只有在隊列被observers時有效. 更新時一步的.
@property(nonatomic, readonly) NSArray<SKPaymentTransaction *> *transactions;
@end
@protocol SKPaymentTransactionObserver <NSObject>
@required
// 事務數據發(fā)生變化的時候調用, 客戶應檢查交易狀態(tài)冈在,并在適當時完成。
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions;
@optional
// 從隊列中刪除事務時調用 (通過此方法引起 finishTransaction:).
- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray<SKPaymentTransaction *> *)transactions;
// 將用戶的購買歷史記錄中的事務添加回隊列時遇到錯誤時發(fā)送按摘。
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error;
// 成功地將用戶購買歷史記錄中的所有事務添加回隊列時發(fā)送包券。
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue;
// 當下載狀態(tài)改變時調用.
- (void)paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray<SKDownload *> *)downloads;
// 當用戶從應用程序商店啟動IAP購買時發(fā)送(iOS11新增)
- (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)payment forProduct:(SKProduct *)product;
@end
NS_ASSUME_NONNULL_END
SKPaymentTransaction
typedef NS_ENUM(NSInteger, SKPaymentTransactionState) {
SKPaymentTransactionStatePurchasing, // 事務正在添加到隊列中.
SKPaymentTransactionStatePurchased, // 事務在隊列中纫谅,用戶已被收費〗蹋客戶端應完成交易付秕。
SKPaymentTransactionStateFailed, // 在添加到隊列前事務被取消或者失敗
SKPaymentTransactionStateRestored, // 從用戶購買的歷史記錄中恢復的事務∈坦客戶端應完成交易询吴。
SKPaymentTransactionStateDeferred, // 事務在隊列中,但其最終狀態(tài)是外部操作而掛起的.
};
@interface SKPaymentTransaction : NSObject {
// 僅僅在狀態(tài)為SKPaymentTransactionFailed時有值
@property(nonatomic, readonly, nullable) NSError *error;
// 僅僅在狀態(tài)為SKPaymentTransactionStateRestored時有效.
@property(nonatomic, readonly, nullable) SKPaymentTransaction *originalTransaction;
// 付款對象
@property(nonatomic, readonly) SKPayment *payment;
// 當前事務有效的下載
@property(nonatomic, readonly) NSArray<SKDownload *> *downloads;
// 事務添加到隊列時的日期亮元。只有在狀態(tài)為skpaymenttransactionstatepur或skpaymenttransactionstaterestated時才有效
@property(nonatomic, readonly, nullable) NSDate *transactionDate;
// 隊列中事物的唯一標識符. 狀態(tài)為SKPaymentTransactionStatePurchased或SKPaymentTransactionStateRestored時有效
@property(nonatomic, readonly, nullable) NSString *transactionIdentifier;
// Only valid if state is SKPaymentTransactionStatePurchased.
@property(nonatomic, readonly, nullable) NSData *transactionReceipt;
// 事務的狀態(tài)
@property(nonatomic, readonly) SKPaymentTransactionState transactionState;
@end