【问题标题】:In App Purchase Objective C Status from appStoreReceiptURL来自 appStoreReceiptURL 的应用购买目标 C 状态
【发布时间】:2020-01-15 10:09:02
【问题描述】:

我是 Objective 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】:

    你的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);
    }
    

    【讨论】:

    • JSON text did not start with array or object and option to allow fragments not set.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多