私は、アプリケーションを開くたびに自動更新サブスクリプションのステータスを確認したいと思います。自動更新可能なサブスクリプションが有効かどうかを確認してください
これは、ユーザーが依然としてサービスに加入していることを確認するためです。これをどのように達成するのですか?
どのような考えですか?ここで
P.S:私はSwiftyStoreKit
私は、アプリケーションを開くたびに自動更新サブスクリプションのステータスを確認したいと思います。自動更新可能なサブスクリプションが有効かどうかを確認してください
これは、ユーザーが依然としてサービスに加入していることを確認するためです。これをどのように達成するのですか?
どのような考えですか?ここで
P.S:私はSwiftyStoreKit
を使用していますが、チェックするために領収書の検証を行うには、いくつかの方法でいただき、ありがとうございますと、サブスクリプションに付与されたユーザーです。
hereと書かれているように、リモートで領収証の検証を行います。レシートをApp Storeのホワイトアプリに送るべきではないと言われています。短い要約:
あなたは、アプリ内購入のリストを取得します。期限切れのサブスクリプションも同様に含まれます。すべてのサブスクリプションを投げ、有効期限を確認する必要があります。それでも有効な場合は、ユーザーにサブスクリプションを付与する必要があります。
私はあなたがSwiftyStoreKitを使用していることを理解しており、ここにはlocal receipt validationのオープンタスクがあります。
のアプリの購入プログラミングガイドを参照してください。はい、私はSwiftyStoreKitを使用していますが、SwiftyStoreKit.restorePurchasesは購入日を確認することができません。つまり、復元された購入の有効性をチェックすることができません – JayVDiyk
はい。あなたは正しいです。同様に、restorePurchases認証(ユーザー名とパスワード)ダイアログを実行するたびに、ユーザーにダイアログが表示されます。 – Ramis
ラミス、そう、それらのrestorePurchasesの日付/有効性を得ることは全く不可能ですか? – JayVDiyk
この機能で確認できます。 swift4
func receiptValidation() {
let SUBSCRIPTION_SECRET = "yourpasswordift"
let receiptPath = Bundle.main.appStoreReceiptURL?.path
if FileManager.default.fileExists(atPath: receiptPath!){
var receiptData:NSData?
do{
receiptData = try NSData(contentsOf: Bundle.main.appStoreReceiptURL!, options: NSData.ReadingOptions.alwaysMapped)
}
catch{
print("ERROR: " + error.localizedDescription)
}
//let receiptString = receiptData?.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
let base64encodedReceipt = receiptData?.base64EncodedString(options: NSData.Base64EncodingOptions.endLineWithCarriageReturn)
print(base64encodedReceipt!)
let requestDictionary = ["receipt-data":base64encodedReceipt!,"password":SUBSCRIPTION_SECRET]
guard JSONSerialization.isValidJSONObject(requestDictionary) else { print("requestDictionary is not valid JSON"); return }
do {
let requestData = try JSONSerialization.data(withJSONObject: requestDictionary)
let validationURLString = "https://sandbox.itunes.apple.com/verifyReceipt" // this works but as noted above it's best to use your own trusted server
guard let validationURL = URL(string: validationURLString) else { print("the validation url could not be created, unlikely error"); return }
let session = URLSession(configuration: URLSessionConfiguration.default)
var request = URLRequest(url: validationURL)
request.httpMethod = "POST"
request.cachePolicy = URLRequest.CachePolicy.reloadIgnoringCacheData
let task = session.uploadTask(with: request, from: requestData) { (data, response, error) in
if let data = data , error == nil {
do {
let appReceiptJSON = try JSONSerialization.jsonObject(with: data)
print("success. here is the json representation of the app receipt: \(appReceiptJSON)")
// if you are using your server this will be a json representation of whatever your server provided
} catch let error as NSError {
print("json serialization failed with error: \(error)")
}
} else {
print("the upload task returned an error: \(error)")
}
}
task.resume()
} catch let error as NSError {
print("json serialization failed with error: \(error)")
}
}
}
とその作品あなたは領収書のアプリセクションに検証する必要があります。 Apple – Paulw11