【问题标题】:appStoreReceiptURL on mainBundle always returns nilmainBundle 上的 appStoreReceiptURL 总是返回 nil
【发布时间】:2013-11-17 04:47:12
【问题描述】:

此方法 appStoreReceiptURL 替代了 SKPaymentTransaction 上已弃用的 transactionReceipt 方法。每个人都说只使用这个调用:

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

如果有收据,这应该返回一个 url。但对我来说没有一个,因为这个值是零,据我所知,它不应该是。我在 iOS 7 上运行并且已经完成了一些应用内购买(设备上的沙盒)。现在我正在尝试添加另一个应用内购买,即自动续订订阅,我需要深入了解收据以获取订阅到期日期。但是我无法通过这个简单的步骤,因为该值始终为零。

有人知道为什么吗?

【问题讨论】:

  • 奇怪。在 iOS 7 下,该方法永远不会返回 nil。 URL 中可能没有文件,但 URL 应该始终有一个值。
  • 我也有同样的问题。你找到解决办法了吗?

标签: ios objective-c in-app-purchase


【解决方案1】:

有点晚了,但可能对某人有用:

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

`

【讨论】:

  • 感谢您的提示!但我需要检查用户是否已经购买了该应用程序。你有什么建议吗?
  • 错了,别这样。刷新可能会请求用户并通过,Apple 明确表示它只能通过用户操作发生。
【解决方案2】:

现在是 iOS 8.4 和 Xcode 6.4,所以历史可能有所不同,但我发现在模拟器中运行时,此方法调用总是返回 nil。在真实设备上,它按照 Apple 记录的方式工作:返回应用收据的存储路径——不保证那里有收据,也不能保证它是有效的收据。

【讨论】:

  • 我想可能是这样,但现在已经很久了,我已经不记得了。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 2015-03-05
  • 2014-08-25
  • 2016-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多