Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ios - appStoreReceiptURL on mainBundle always returns nil

This method appStoreReceiptURL is the replacement for the deprecated transactionReceipt method on SKPaymentTransaction. And everyone says to just use this call instead:

NSURL *theURL = [[NSBundle mainBundle] appStoreReceiptURL];

This is supposed to return a url to a receipt if there is one. But for me there isn't one, as this value is nil, and as far as I can tell it shouldn't be. I'm running on iOS 7 and have done a few in-app purchases (sandbox on the device). Now I'm trying to add another in-app purchase, an auto-renewing subscription, and I need to dig into the receipt to get the subscription expiration date. But I can't get past this simple step because the value is simply always nil.

Does anyone know why?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A bit late, but it may be of use to someone:

-(void) someMethod {
    NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL];
    if ([[NSFileManager defaultManager] fileExistsAtPath:[receiptUrl path]])
    {

        NSData *ios7ReceiptData = [NSData dataWithContentsOfURL:receiptUrl];
        //Do stuff

    } else {
        NSLog(@"iOS 7 AppReceipt not found %@, refreshing...",iapID);
        SKReceiptRefreshRequest *refreshReceiptRequest = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:@{}];
        refreshReceiptRequest.delegate = self;
        [refreshReceiptRequest start];
    }
}

- (void)requestDidFinish:(SKRequest *)request {
    if([request isKindOfClass:[SKReceiptRefreshRequest class]])
    {
        //SKReceiptRefreshRequest
        NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL];
        if ([[NSFileManager defaultManager] fileExistsAtPath:[receiptUrl path]]) {
            NSLog(@"App Receipt exists");
            //Do stuff
        } else {
            NSLog(@"Receipt request done but there is no receipt");

            // This can happen if the user cancels the login screen for the store.
            // If we get here it means there is no receipt and an attempt to get it failed because the user cancelled the login.
            //[self trackFailedAttempt];
        }
    }
}

`


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...