

Tpinestreceipt는 앱 구매 영수증에서 Apple을 읽고 검증하기위한 가볍고 순수한 스위트 라이브러리입니다.
참고 : Objective-C 프로젝트의 tpinestreceipt-Objective-C 프로젝트에서 tpinesceipt를 사용하려면이 안내서를 따르십시오.
Cocoapods를 사용하여 tpinesceipt를 프로젝트에 통합하려면 Podfile 에 지정하십시오.
platform :ios , '12.0'
target 'YOUR_TARGET' do
use_frameworks!
pod 'TPInAppReceipt'
end그런 다음 다음 명령을 실행합니다.
$ pod install tpinesceipt를 사용하려는 신속한 파일에서 import TPInAppReceipt 로 프레임 워크를 가져 오십시오.
Apple의 Swift 패키지 관리자를 사용하여 통합하려면 다음을 Package.swift 에 종속성으로 추가하십시오.
. package ( url : " https://github.com/tikhop/TPInAppReceipt.git " , . upToNextMajor ( from : " 3.0.0 " ) ) 그런 다음 tpinestreceipt를 사용하려는 대상의 종속성으로 "TPInAppReceipt" 지정하십시오.
마지막으로 다음 명령을 실행하십시오.
swift package update InAppReceipt 객체는 영수증 및 관련 구매에 대한 정보를 캡슐화합니다. 인앱 구매 영수증을 확인하려면 InAppReceipt 객체를 작성해야합니다.
InAppReceipt 객체를 만들려면 원시 영수증 데이터를 제공하거나 로컬 영수증을 초기화 할 수 있습니다.
do {
/// Initialize receipt
let receipt = try InAppReceipt . localReceipt ( )
// let receipt = try InAppReceipt() // Returns local receipt
// let receiptData: Data = ...
// let receipt = try InAppReceipt.receipt(from: receiptData)
} catch {
print ( error )
}
TPInAppReceipt 인앱 구매 영수증을 확인하기위한 다양한 편의 방법을 제공합니다.
/// Verify hash
try ? receipt . verifyHash ( )
/// Verify bundle identifier
try ? receipt . verifyBundleIdentifier ( )
/// Verify bundle version
try ? receipt . verifyBundleVersion ( )
/// Verify signature
try ? receipt . verifySignature ( )
/// Validate all at once
do {
try receipt . verify ( )
} catch IARError . validationFailed ( reason : . hashValidation ) {
// Do smth
} catch IARError . validationFailed ( reason : . bundleIdentifierVerification ) {
// Do smth
} catch IARError . validationFailed ( reason : . signatureValidation ) {
// Do smth
} catch {
// Do smth
}참고 : Apple은 앱이 출시 된 직후에 영수증 검증을 수행하는 것이 좋습니다. 추가 보안을 위해 응용 프로그램이 실행되는 동안이 점검을 주기적으로 반복 할 수 있습니다. 참고 : iOS에서 유효성 검사가 실패하면 먼저 영수증을 새로 고치십시오.
앱이 자동 갱신 가능한 구독에 대한 입문 가격을 제공하는 경우 소개 또는 일반 가격의 올바른 가격에 이의를 제기해야합니다.
InAppReceipt 클래스는 입문 가격 자격을 결정하기위한 인터페이스를 제공합니다. 가장 간단하게, 동일한 가입 그룹에 속하는 제품 식별자 Set 제공하십시오.
// Check whether user is eligible for any products within the same subscription group
var isEligible = receipt . isEligibleForIntroductoryOffer ( for : [ " com.test.product.bronze " , " com.test.product.silver " , " com.test.product.gold " ] )참고 : 사용자가 입문 제안을받을 자격이 있는지 확인하려면 먼저 영수증을 초기화하고 검증 한 다음 자격을 확인해야합니다.
/// Initialize receipt
let receipt = try ! InAppReceipt . localReceipt ( )
/// Base64 Encoded Receipt
let base64Receipt = receipt . base64
/// Check whether receipt contains any purchases
let hasPurchases = receipt . hasPurchases
/// All auto renewable `InAppPurchase`s,
let purchases : [ InAppPurchase ] = receipt . autoRenewablePurchases
/// all ACTIVE auto renewable `InAppPurchase`s,
let activePurchases : [ InAppPurchase ] = receipt . activeAutoRenewableSubscriptionPurchases // Retrieve Original TransactionIdentifier for Product Name
receipt . originalTransactionIdentifier ( ofProductIdentifier : subscriptionName )
// Retrieve Active Auto Renewable Subscription's Purchases for Product Name and Specific Date
receipt . activeAutoRenewableSubscriptionPurchases ( ofProductIdentifier : subscriptionName , forDate : Date ( ) )
// Retrieve All Purchases for Product Name
receipt . purchases ( ofProductIdentifier : subscriptionName ) 필요한 경우이 방법을 사용하여 작업중인 영수증이 최신 상태인지 확인하십시오.
InAppReceipt . refresh { ( error ) in
if let err = error
{
print ( err )
} else {
initializeReceipt ( )
}
} tpinestreceipt는 MIT 라이센스에 따라 릴리스됩니다. 자세한 내용은 라이센스를 참조하십시오.