appStoreReceiptURL on mainBundle always returns nil

前端 未结 2 551
忘了有多久
忘了有多久 2020-12-16 05:32

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

相关标签:
2条回答
  • 2020-12-16 05:56

    It's now iOS 8.4 and Xcode 6.4 so maybe history is different, but I find this method call always returns nil when running in the simulator. On a real device it works as documented by Apple: The path to where the app receipt is intended to be stored is returned -- with no guarantee that either there is a receipt there nor that it is a valid receipt.

    0 讨论(0)
  • 2020-12-16 06:01

    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];
            }
        }
    }
    

    `

    0 讨论(0)
提交回复
热议问题