自动续订内购订阅用户流量&刷新收据

Auto renewable IAP subscription user flow & refreshing receipts

我正在使用图书馆 RMStore - 这是我目前拥有的图书馆。

1) 购买自动续订订阅并验证 returned 收据。

[[RMStore defaultStore]addPayment:[Environment environment].premiumProductIAPId success:^(SKPaymentTransaction *transaction) {
  [[RMStore defaultStore].receiptVerificator verifyTransaction:transaction success:^{

    //enable premium service

  } failure:^(NSError *error) {

  }];
} failure:^(SKPaymentTransaction *transaction, NSError *error) {

}];

2) 在每次应用启动时,检查订阅在该日期是否有效,如果有效则启用高级服务

RMAppReceipt *appReceipt = [RMAppReceipt bundleReceipt];
if (appReceipt){
  NSInteger isActive = [appReceipt containsActiveAutoRenewableSubscriptionOfProductIdentifier:[Environment environment].premiumProductIAPId forDate:[NSDate date]];
  //enable premium service if active
}

3) 如果用户在另一台设备上启动应用程序,允许他们通过刷新收据(如果存在)并检查购买中是否有有效订阅来恢复购买。

"In most cases, all your app needs to do is refresh its receipt and deliver the products in its receipt."

- 来自指南。这是代码:

[[RMStore defaultStore]refreshReceiptOnSuccess:^{

  if ([receipt containsActiveAutoRenewableSubscriptionOfProductIdentifier:[Environment environment].premiumProductIAPId forDate:[NSDate date]]){
   //enable
  }else{ 
   //no longer active
  }
} failure:^(NSError *error) {

}];

我的问题:

我将尝试回答我的问题。

可能有续订,但在启动时未首先检测到,因此订阅显示为无效。

我添加了一个观察者来监听完成的交易(RMStore 扩展了这个 StoreKit 功能)。

每次收到此通知时,我都会检查(现已更新)有效订阅收据并启用高级服务(如果有的话)。

- (void)storePaymentTransactionFinished:(NSNotification*)notification
{
  BOOL isActive = [[RMAppReceipt bundleReceipt] containsActiveAutoRenewableSubscriptionOfProductIdentifier:[Environment environment].premiumProductIAPId forDate:[NSDate date]];
  if (isActive){
    //enable premium
  }
}  

这似乎有效。如果有人有任何其他建议,请告诉我。