Ungültige Transaktion Quittung zurückgegeben appStoreReceiptURL (NSData), in iOS 7
Verwende ich folgende Methode, um den Empfang von Daten:
//Use this method instead of accessing transaction.transactionReceipt directly!
- (NSData *)appStoreReceiptForPaymentTransaction:(SKPaymentTransaction *)transaction {
NSData *receiptData = nil;
//This is just a quick/dummy implementation!
if (kiOS7) {
NSURL *receiptFileURL = [[NSBundle mainBundle] appStoreReceiptURL];
receiptData = [NSData dataWithContentsOfURL:receiptFileURL]; //Returns valid NSData object
} else {
receiptData = transaction.transactionReceipt; //Returns valid NSData object
}
return receiptData;
}
Ich verwende folgenden code zum Lesen der JSON-Empfang:
NSData *receipt = [self appStoreReceiptForPaymentTransaction:transaction];
NSError *error = nil;
NSDictionary *receiptDict = [receipt dictionaryFromPlistData:&error];
NSString *transactionPurchaseInfo = [receiptDict objectForKey:@"purchase-info"];
NSString *decodedPurchaseInfo = [NSString stringWithUTF8String:[[NSData dataFromBase64String:transactionPurchaseInfo] bytes]];
NSDictionary *purchaseInfoDict = [[decodedPurchaseInfo dataUsingEncoding:NSUTF8StringEncoding] dictionaryFromPlistData:&error];
NSString *transactionID = [purchaseInfoDict objectForKey:@"transaction-id"];
NSString *purchaseDateString = [purchaseInfoDict objectForKey:@"purchase-date"];
NSString *signature = [receiptDict objectForKey:@"signature"];
NSString *signatureDecoded = [NSString stringWithUTF8String:[[NSData dataFromBase64String:signature] bytes]];
//Convert the string into a date
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];
NSDate *purchaseDate = [dateFormat dateFromString:[purchaseDateString stringByReplacingOccurrencesOfString:@"Etc/" withString:@""]];
NSLog(@"Raw receipt content: \n%@", [NSString stringWithUTF8String:[receipt bytes]]);
NSLog(@"Purchase Info: %@", purchaseInfoDict);
NSLog(@"Transaction ID: %@", transactionID);
NSLog(@"Purchase Date: %@", purchaseDate);
NSLog(@"Signature: %@", signatureDecoded);
Den dictionaryFromPlistData:
Methode gibt die richtige NSDictionary
- Objekt für die Daten zurückgegeben transactionReceipt
, aber es gibt nil
mit Daten zurückgegeben, die mit appStoreReceiptURL
-- und consequetly bekomme ich keine gültige Quittung!
- (NSDictionary *)dictionaryFromPlistData:(NSError **)outError {
NSError *error;
NSDictionary *dictionaryParsed = [NSPropertyListSerialization propertyListWithData:self
options:NSPropertyListImmutable
format:nil
error:&error];
if (!dictionaryParsed) {
if (error) {
*outError = error;
}
return nil;
}
return dictionaryParsed;
}
Warum ist nicht der obige code funktioniert in iOS 7?
Nur zu wiederholen, dictionaryFromPlistData:
korrekt konvertiert die NSData
zurückgegeben transaction.transactionReceipt
.
Du musst angemeldet sein, um einen Kommentar abzugeben.
iOS 7 geändert hat, wie Eingangs Validierung erfolgt. Ich ging durch den genauen Pfad sind Sie nach unten und bekam die gleichen Ergebnisse. Was ich fand, war, dass der Empfang von
[[NSBundle mainBundle] appStoreReceiptURL]
erfordert eine andere Methode für die Decodierung als die Vorherigetransaction.transactionReceipt
.Hier ist ein Ausschnitt aus Apple docs:
Wenn Sie ' re suchen für eine schnelle Lösung, ich habe den Erfolg gesehen hier: https://github.com/rmaddy/VerifyStoreReceiptiOS