Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS IAP, how to judge multiple user at the same device

For example: There are two different game characters in a single iPhone device, we call it A and B.

First, app user login as A, he perform an IAP action, the A logout without the purchase completed.

Then, app user login as B, then purchase finish event arrival, this is the problem, how to judge the receipt belongs to A, not B.

I googled, found SKMutablePayment.requestData may be used for solve this problem, but Apple Document told me this is a reserved property, and must be nil, or else then payment will be reject.

requestData Reserved for future use. (read-only)

@property(nonatomic, copy, readonly) NSData *requestData Discussion The default value is nil. If requestData is not nil, your payment request will be rejected.

Availability Available in iOS 3.0 and later. Declared In SKPayment.h

like image 565
user1298239 Avatar asked Mar 26 '14 02:03

user1298239


1 Answers

thanks for everyone's reply

finally, I found SKMutablePayment.applicationUsername can save my private account username, but It only available on iOS7.0.

save:

SKMutablePayment* payment = [SKMutablePayment paymentWithProduct:product];
payment.applicationUsername = @"my_username_1001";

read:

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{            
     for (SKPaymentTransaction* trans in transactions) {
        switch (trans.transactionState) {
            case SKPaymentTransactionStateFailed:
                [[SKPaymentQueue defaultQueue] finishTransaction:trans];
                break;
            case SKPaymentTransactionStatePurchased:
                // got private user account here
                NSString* applicationUsername = [[trans payment] applicationUsername];
                break;
            case SKPaymentTransactionStatePurchasing:
                break;
            case SKPaymentTransactionStateRestored:
                break;
        }
    }
}
like image 73
user1298239 Avatar answered Sep 29 '22 11:09

user1298239