应用内购买appStoreReceiptURL为空

时间:2017-12-03 16:56:13

标签: ios swift in-app-purchase

2个月前我在我的应用程序中进行了自动更新购买,一切都很好用沙箱。但现在我无法通过NSBundle.mainBundle()获得收据.appStoreReceiptURL此路径不会退出。怎么会这样? 2个月前收到了收据(或更少)。请帮帮我!这就是我收据的方式(swift 2) -

static func receipt() -> String {
    print("RECEPT URL", NSBundle.mainBundle().appStoreReceiptURL)

    guard let receiptUrl = NSBundle.mainBundle().appStoreReceiptURL, let receiptPath = receiptUrl.path else { return "" }
    let fileManager = NSFileManager.defaultManager()
    if fileManager.fileExistsAtPath(receiptPath){
        var receiptData: NSData?
        do {
            receiptData = try NSData(contentsOfURL: receiptUrl, options: NSDataReadingOptions.DataReadingMappedAlways)
        }
        catch {
            print("ERROR: " )
        }

        //guard let receiptData = NSData(contentsOfURL: receiptUrl) else { return "" }
        if let receiptString = receiptData?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) {
            print("REC", receipt, receiptString)

            return receiptString
        }
    }
    return ""
}

1 个答案:

答案 0 :(得分:0)

根据文档,appStoreReceiptURL可能会或可能不会指向收据的文件。您可以使用SKReceiptRefreshRequest请求收据刷新。