我在尝试测试应用内购买(iOS 8+ Swift 1.2)时遇到了一些奇怪的问题。我在iTunes连接帐户中有一个耗材产品,我可以检索产品和产品详细信息。在我想要开始购买时,EXC_BAD_ACCESS崩溃之前的代码行在
//Transaction has been made
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
if(list.count == 0){
return
}
//code
for transaction:AnyObject in transactions{
var trans = transaction as! SKPaymentTransaction
println(trans.error)
switch trans.transactionState {
case .Purchasing:
println("Purchasing...The transaction is being processed by the App Store.")
case .Purchased:
println("Buy, ok unlock iap here")
println(p.productIdentifier)
queue.finishTransaction(trans)
let prodID = p.productIdentifier! as String
switch prodID {
case iapID:
println("send submission")
saveSuperSubmission()
default:
println("IAP not Setup")
}
case .Failed:
println("buy error")
queue.finishTransaction(trans)
default:
println("updatedTransactions: \(trans.transactionState.rawValue)")
break;
}
}
}
点击。采购后,它会立即崩溃。现在在询问我的密码后在物理设备上,出现了购买产品的确认提示,当我选择购买时,另一个提示声明"此应用内购买已经被购买"。一旦崩溃发生,Xcode就不会在跟踪中显示我的任何代码。它显示了UIApplicationMain以及如下所示的内容
0x2daf0a04 <+1436>: blx 0x2e1ae2c8 ; symbol stub for: CFDictionaryRemoveAllValues$shim
0x2daf0a08 <+1440>: ldr r0, [sp, #0x2c]
0x2daf0a0a <+1442>: ldr r1, [sp, #0x18]
答案 0 :(得分:0)
将您的代码与上一个项目中的代码进行比较。
我会在开头做一个更安全的演员表(你会受到一些意外状态的保护):
if let trans = transaction as? SKPaymentTransaction
然后你我也会纠正
default:
println("updatedTransactions: \(trans.transactionState.rawValue)")
queue.finishTransaction(trans)
因为你也可以从8.0获得SKPaymentTransactionStateDeferred
,它应该完成。