【发布时间】:2013-02-04 03:15:34
【问题描述】:
我是 IOS 新手。目前正在我的报亭应用程序中进行应用程序购买实施。我已在我的报亭应用程序中实施自动更新订阅。我如何检查应用程序购买自动更新订阅是否有效?
【问题讨论】:
-
此链接stackoverflow.com/questions/22680059/… 可能会对您有所帮助。
标签: xcode in-app-purchase
我是 IOS 新手。目前正在我的报亭应用程序中进行应用程序购买实施。我已在我的报亭应用程序中实施自动更新订阅。我如何检查应用程序购买自动更新订阅是否有效?
【问题讨论】:
标签: xcode in-app-purchase
创建订阅时,您需要存储收据对象。您可以使用收据来确定它所代表的订阅是否有效。
我正在使用 CargoBay (https://github.com/mattt/CargoBay) 来帮助处理 StoreKit。它有一个方法:
[[CargoBay sharedManager] verifyTransaction:transaction password:nil success:^(NSDictionary *receipt) {
NSLog(@"Receipt: %@", receipt);
} failure:^(NSError *error) {
NSLog(@"Error %d (%@)", [error code], [error localizedDescription]);
}];
【讨论】:
今天,我遇到了这个问题。 关注Apple doc这里,我用这种方式检查订阅是否过期。
这是我在 Objective-C 中的代码。
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:resData options:0 error:&error];
// this is response from AppStore
NSDictionary *dictLatestReceiptsInfo = jsonResponse[@"latest_receipt_info"];
long long int expirationDateMs = [[dictLatestReceiptsInfo valueForKeyPath:@"@max.expires_date_ms"] longLongValue];
long long requestDateMs = [jsonResponse[@"receipt"][@"request_date_ms"] longLongValue];
isValidReceipt = [[jsonResponse objectForKey:@"status"] integerValue] == 0 && (expirationDateMs > requestDateMs);
希望对您有所帮助。
【讨论】: