首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mainBundle上的appStoreReceiptURL始终返回nil

mainBundle上的appStoreReceiptURL始终返回nil
EN

Stack Overflow用户
提问于 2013-11-17 12:47:13
回答 2查看 6.9K关注 0票数 6

此方法appStoreReceiptURL是SKPaymentTransaction上不推荐使用的transactionReceipt方法的替代方法。每个人都说用这个调用来代替:

代码语言:javascript
复制
NSURL *theURL = [[NSBundle mainBundle] appStoreReceiptURL];

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

有人知道为什么吗?

EN

回答 2

Stack Overflow用户

发布于 2014-01-09 20:35:11

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

代码语言:javascript
复制
-(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];
        }
    }
}

`

票数 25
EN

Stack Overflow用户

发布于 2015-08-21 01:28:01

它现在是Xcode8.4和Xcode6.4,所以历史可能有所不同,但我发现当在模拟器中运行时,这个方法调用总是返回nil。在真实的设备上,它的工作原理与Apple的文档相同:返回应用程序收据的存储路径--不能保证那里有收据,也不能保证它是有效的收据。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20027322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档