来自appStoreReceiptURL的应用内购买目标C状态

问题描述 投票:0回答:1

我是我发现的目标c的新手

NSURL* url = [[NSBundle mainBundle] appStoreReceiptURL];
NSLog(@"receiptUrl %@",[url path]);

用于检查应用程序购买状态以进行验证或类似操作。

我如何获得这个:作为NSString([INITIAL_BUY,CANCEL

。INITIAL_BUY最初购买的订阅。.CANCEL订购被Apple客户支持取消。.RENEWAL成功更新了已过期的订阅。.INTERACTIVE_RENEWAL客户可以通过使用应用程序界面或在App Store中的帐户设置中以互动方式续订订阅。.DID_CHANGE_RENEWAL_PREFERENCE客户更改了在下一次订阅续订时生效的计划。

ios objective-c in-app-purchase storekit in-app-subscription
1个回答
0
投票

您拥有的url只是收据的位置,因此您首先需要阅读收据文件:

- (NSData *)loadReceipt
{
    LogMethodCall

    NSURL *url = NSBundle.mainBundle.appStoreReceiptURL;
    if (!url) return nil;

    NSError *error;
    NSData *data = [NSData dataWithContentsOfURL:url options:0 error:&error];
    if (data) return data;

    NSLog(@"Error loading receipt data: %@", error.localizedDescription);
    return nil;
}

现在您具有收据数据,您可以将其转换为NSDictionary并查看其内容:

NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[self loadReceipt]options:0 error:&error];
if (!error) {
   NSLog(@"%@", json);
} else {
   NSLog(@"%@", error);
}
© www.soinside.com 2019 - 2024. All rights reserved.