我按照此链接进行应用内购买(http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/comment-page-20/#comment-22550)。使用Sandbox测试用户(有美国领土)我可以成功购买产品。如果再次按下购买按钮,我需要恢复产品。我怎么知道产品是否已经购买?我需要验证自动续订订阅的收据。我能怎么做?使用目标c。
答案 0 :(得分:0)
首先,实施自定义付款类符合协议SKPaymentTransactionObserver
。此课程可用于接收付款信息:
<强>·H 强>
#import <StoreKit/StoreKit.h>
@interface PaymentObserver : NSObject<SKPaymentTransactionObserver>
+ (instancetype)sharedInstance;
@end
<强>的.m:强>
@implementation PaymentObserver
+ (instancetype)sharedInstance{
static PaymentObserver * instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[PaymentObserver alloc] init];
});
return instance;
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
// Call the appropriate custom method for the transaction state.
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStateDeferred:
break;
case SKPaymentTransactionStateFailed:
break;
case SKPaymentTransactionStatePurchased:
break;
case SKPaymentTransactionStateRestored:
//Purchased product info goes here. Get more details in transaction object.
break;
default:
break;
}
}
}
然后,在AppDelegate
中,使用上述类检索付款信息:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//......
[[SKPaymentQueue defaultQueue] addTransactionObserver:[PaymentObserver sharedInstance]];
//......
}
PaymentObserver类将从AppStore获取购买的产品信息。
主程序是这样的。您将有更多细节要处理它们。