IAPs actually validating the receipt (Swift)

后端 未结 3 2046
时光取名叫无心
时光取名叫无心 2021-02-06 17:34

I have been trying to implement receipt validation in my spritekit game. I have been following various tutorial and basically ended up with this code

enum Reques         


        
3条回答
  •  不知归路
    2021-02-06 17:40

    Today, I have trouble with this problem. And I referenced on this answer. But I discover new way to check subscription is expired or not.

    This is my code in 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);
    

    Hope this help.

提交回复
热议问题