此方法appStoreReceiptURL是SKPaymentTransaction上不推荐使用的transactionReceipt方法的替代方法。每个人都说用这个调用来代替:
NSURL *theURL = [[NSBundle mainBundle] appStoreReceiptURL];如果有收据的话,这会返回一个url给收据。但对我来说没有一个,因为这个值是零,而且据我所知它不应该是零。我在iOS 7上运行,并进行了一些应用内购买(设备上的沙盒)。现在,我正在尝试添加另一个应用内购买,即自动续订订阅,我需要深入查看收据以获取订阅到期日期。但是我不能通过这个简单的步骤,因为这个值总是为零。
有人知道为什么吗?
发布于 2014-01-09 20:35:11
有点晚了,但它可能对某些人有用:
-(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];
}
}
}`
发布于 2015-08-21 01:28:01
它现在是Xcode8.4和Xcode6.4,所以历史可能有所不同,但我发现当在模拟器中运行时,这个方法调用总是返回nil。在真实的设备上,它的工作原理与Apple的文档相同:返回应用程序收据的存储路径--不能保证那里有收据,也不能保证它是有效的收据。
https://stackoverflow.com/questions/20027322
复制相似问题