我想将我的代码源从swift 2.3转换为swift 3 但我不能,你可以帮助我吗?
for transaction:AnyObject in transactions {
let trans = transaction as! SKPaymentTransaction
print(trans.error)
switch trans.transactionState {
case .purchased:
let prodID = buyingProduct
switch prodID {
case ?adsid:
print("remove ads")
defaults.set(true, forKey: "adsremoved")
didbuyad = true
case ?levelsid:
print("add levels to account")
self.unlockAllLevels()
default:
print("IAP not setup")
}
SKPaymentQueue.default().finishTransaction(transaction as!
SKPaymentTransaction)
queue.finishTransaction(trans)
break;
case .failed:
print("buy error")
SKPaymentQueue.default().finishTransaction(transaction as!
SKPaymentTransaction)
queue.finishTransaction(trans)
break;
default:
print("default")
break;
}
}
}
不会返回正确的值
答案 0 :(得分:0)
只需删除"?"来自案例。
for transaction:AnyObject in transactions {
let trans = transaction as! SKPaymentTransaction
print(trans.error)
switch trans.transactionState {
case .purchased:
let prodID = buyingProduct
switch prodID {
case adsid:
print("remove ads")
defaults.set(true, forKey: "adsremoved")
didbuyad = true
case levelsid:
print("add levels to account")
self.unlockAllLevels()
default:
print("IAP not setup")
}
SKPaymentQueue.default().finishTransaction(transaction as!
SKPaymentTransaction)
queue.finishTransaction(trans)
break;
case .failed:
print("buy error")
SKPaymentQueue.default().finishTransaction(transaction as!
SKPaymentTransaction)
queue.finishTransaction(trans)
break;
default:
print("default")
break;
}
}