這似乎是我研究中的一個常見問題In App Purchase不恢復與沙箱用戶的交易
這些都是在真實設備上完成的。
我的應用程序購買了應用程序內購買,但是當我來恢復應用程序內購買時,它沒有反應。
在此之後,
@IBAction func RestoreItem(_ sender: Any) {
SKPaymentQueue.default().restoreCompletedTransactions()
print("RESTORING PURCHASES")
}
它應該叫products request
然後payment queue
功能。 我已閱讀,如果iTunes帳戶不包含未調用的購買。 如果我運行應用程序併購買每個項目的應用程序購買好,並說這些已購買之前,所以它知道購買歷史
我不明白的是,爲什麼,如果它知道項目已購買它不在調用函數後發生反應(如上所示)。
如果我在我的設備上完全退出我的iTunes帳戶並觸發上面的操作,它會要求我登錄到我的帳戶。我這樣做(在我以前購買的同一帳戶),它並不會觸發product request
(我有NSlog
語句都過來看我在什麼狀態)
任何想法,因爲我一直在爲此而努力了好幾天。 謝謝
我已經包含在下面的代碼,這適用於購買(僅供參考)。
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
print("product request")
let myProduct = response.products
for product in myProduct {
print("product added")
print(product.productIdentifier)
print(product.localizedTitle)
print(product.localizedDescription)
print(product.price)
list.append(product)
}
}
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
print("add payment")
for transaction: AnyObject in transactions {
let trans = transaction as! SKPaymentTransaction
print(trans.error as Any)
switch trans.transactionState {
case SKPaymentTransactionState.purchased:
print("buy ok, unlock IAP HERE")
print(p.productIdentifier)
let prodID = p.productIdentifier
switch prodID {
case "com.clivedancey.social":
print("Social Reality Unlocked")
outBuySocial.setTitle("Social Reality Enabled", for: UIControlState.normal)
SocialReality()
case "com.clivedancey.inapp":
print("MAIN UPGRADE UNLOCKED")
outBuyMain.setTitle(" Main Upgrade Complete", for: UIControlState.normal)
mainunlock()
default:
print("IAP not setup")
}
queue.finishTransaction(trans)
case SKPaymentTransactionState.restored:
print("buy ok, unlock IAP HERE")
print(p.productIdentifier)
let prodID = p.productIdentifier
switch prodID {
case "com.clivedancey.social":
print("Social Reality Unlocked")
outBuySocial.setTitle("Social Reality Enabled", for: UIControlState.normal)
SocialReality()
outTransactionLabel.text = " Purchases restored"
case "com.clivedancey.inapp":
print("MAIN UPGRADE UNLOCKED")
outBuyMain.setTitle(" Main Upgrade Complete", for: UIControlState.normal)
outTransactionLabel.text = " Purchases restored1"
mainunlock()
default:
print("IAP not setup")
}
queue.finishTransaction(trans)
case.failed:
print("buy error")
queue.finishTransaction(trans)
break
default:
print("Default")
break
}
}
}
喜,「反應過來」是由外部編輯器改變了,我的意思是沒有做任何事情,我有所有額外的代碼和購買工作正常,但是當我恢復什麼都沒有發生..在日誌中說'無'旁邊應該說應用程序購買名稱..可能是其沙箱用戶問題......還有關於你的代碼和我的產品標識符似乎並沒有被識別當我恢復,但當我購買.. –
很高興我沒有解釋「反應」不正確。這聽起來像你正在編碼購買,我希望註銷後提示登錄。另外,我從來沒有遇到沙箱用戶的問題。我唯一想知道的其他事情 - 如果您(1)進行了購買,然後(2)刪除了應用程序,然後(3)重新安裝了應用程序並嘗試還原?這是我總是測試*非消耗品*購買的情況。你沒有提到嘗試這個 - 只在不需要的時候嘗試恢復。 – dfd
多數民衆贊成在罰款,是的,嘗試添加購買,刪除應用程序,從Xcode重新加載,然後恢復和虛無,seems,似乎認爲購買還沒有根據日誌,虐待繼續嘔吐在它,謝謝你的幫幫我。我已經標記你的答案是好的。編輯 –