Я пытаюсь внедрить проверку квитанции в приложении в приложении iOS.Я следовал этому руководству и использую пример проекта, предоставленный в качестве основы для работы над своим собственным приложением.
Вот проблема, с которой я сталкиваюсь в данный момент.В функции validateReceipt ():
func validateReceipt() {
......
receipt = Receipt()
if let receiptStatus = receipt?.receiptStatus { // Critical point.
...... // A lot of important things happening here.
}
......
}
Следуя тому, что происходит в отладчике, я вижу, что при достижении строки с комментариями: // Критическая точка .У меня есть квитанция не ноль , но:
receipt?.receiptStatus == nil
В чем может быть причина этого?Я предположил, что сделал что-то не так в пути, но не знаю, что.
Чтобы прояснить ситуацию, ниже следует определение класса Receipt, взятое из руководства:
/// Copyright (c) 2018 Razeware LLC
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
/// distribute, sublicense, create a derivative work, and/or sell copies of the
/// Software in any work that is designed, intended, or marketed for pedagogical or
/// instructional purposes related to programming, coding, application development,
/// or information technology. Permission for such use, copying, modification,
/// merger, publication, distribution, sublicensing, creation of derivative works,
/// or sale is expressly withheld.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
import UIKit
enum ReceiptStatus: String {
case validationSuccess = "This receipt is valid."
case noReceiptPresent = "A receipt was not found on this device."
case unknownFailure = "An unexpected failure occurred during verification."
case unknownReceiptFormat = "The receipt is not in PKCS7 format."
case invalidPKCS7Signature = "Invalid PKCS7 Signature."
case invalidPKCS7Type = "Invalid PKCS7 Type."
case invalidAppleRootCertificate = "Public Apple root certificate not found."
case failedAppleSignature = "Receipt not signed by Apple."
case unexpectedASN1Type = "Unexpected ASN1 Type."
case missingComponent = "Expected component was not found."
case invalidBundleIdentifier = "Receipt bundle identifier does not match application bundle identifier."
case invalidVersionIdentifier = "Receipt version identifier does not match application version."
case invalidHash = "Receipt failed hash check."
case invalidExpired = "Receipt has expired."
}
class Receipt {
var receiptStatus: ReceiptStatus?
var bundleIdString: String?
var bundleVersionString: String?
var bundleIdData: Data?
var hashData: Data?
var opaqueData: Data?
var expirationDate: Date?
var receiptCreationDate: Date?
var originalAppVersion: String?
var inAppReceipts: [IAPReceipt] = []
static public func isReceiptPresent() -> Bool {
if let receiptUrl = Bundle.main.appStoreReceiptURL,
let canReach = try? receiptUrl.checkResourceIsReachable(),
canReach {
return true
}
return false
}
}
На самом деле, проверяя состояние переменной получения (когда она существует) в отладчике, я вижу следующее:
(lldb) p receipt
(MyApp).Receipt?) $R0 = 0x0000000281516ac0 {
receiptStatus = nil
bundleIdString = nil
bundleVersionString = nil
bundleIdData = nil
hashData = nil
opaqueData = nil
expirationDate = nil
receiptCreationDate = nil
originalAppVersion = nil
inAppReceipts = 0 values {}
}
Другими словами, он обнаруживается заполненным нулями.