AppStoreReceiptURL on mainBundle always returns nil

This appStoreReceiptURL method is a replacement for the deprecated Receipt transaction method with SKPaymentTransaction. And everyone says just use this call:

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

It is intended to return the URL of the receipt, if any. But for me there is not one, since this value is equal to zero, and as far as I can judge, this should not be. I work on iOS 7 and made some in-app purchases (sandbox on the device). Now I'm trying to add another purchase in the application, a subscription to an automatic renewal of a subscription, and I need to look at the receipt to get the validity period of the subscription. But I cannot go through this simple step, because the value is always always zero.

Does anyone know why?

+4
source share
2 answers

A little late, but it may be useful 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];
        }
    }
}

`

+22
source

Now it's iOS 8.4 and Xcode 6.4, so maybe the story is different, but I find that this method call always returns nil when run in the simulator. On a real device, this works as documented by Apple. The path returns to where it is supposed to save the receipt of the application - without a guarantee that there is a receipt or that it is a valid receipt.

+1
source

All Articles