I have an in-app purchase, which is an auto-renewal subscription. From the completed purchase in the application, I should be able to get the expiration date of the subscription so that I know when the subscription is no longer valid. I understand what this means (now, starting with iOS 7), starting with appStoreReceiptURL, getting the data behind it, and then somehow from there I can access the in-app purchase items.
But from there it is foggy, and none of the code examples I found on the Internet seem to work. Many of them are deprecated for iOS 7. Most of them do not do subscriptions at all. I really need a sample code that goes from appStoreReceiptURL to the expiration date of the subscription in a straight line, with the least number of lines of code between them. For some reason this seems extremely complicated, but I don't understand why. Often people include validation of receipt validation, which seems like a good idea, but it also adds another huge level of complexity that hides my main goal, and this authentication code always seems to be inoperative. And where I always seem to get on the wall, I take NSData and base64 encode it. It seems to be like this:
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSLog(@"receiptURL:%@", receiptURL);
NSData *receiptData = [NSData dataWithContentsOfURL:receiptURL];
NSLog(@"receiptData:%@", receiptData);
NSString *receiptString = [self base64forData:receiptData];
NSLog(@"receiptString:%@", receiptString);
Where the base64forData method is as follows:
+ (NSString*)base64forData:(NSData*)theData {
const uint8_t* input = (const uint8_t*)[theData bytes];
NSInteger length = [theData length];
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t* output = (uint8_t*)data.mutableBytes;
NSInteger i;
for (i=0; i < length; i += 3) {
NSInteger value = 0;
NSInteger j;
for (j = i; j < (i + 3); j++) {
value <<= 8;
if (j < length) {
value |= (0xFF & input[j]);
}
}
NSInteger theIndex = (i / 3) * 4;
output[theIndex + 0] = table[(value >> 18) & 0x3F];
output[theIndex + 1] = table[(value >> 12) & 0x3F];
output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}
return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
}
URL, . , , nil. . , URL , ReceiptData, receiptString . , base64forData , , , ?
SKPaymentTransaction, iOS 7?