dar*_*iaa 14 storekit in-app-purchase ios
如何检查用户是否点击了取消按钮(当他被问到是否要购买smth时,或者他是否已购买此SKProduct是否要下载它)?
现在我只是在paymentQueue:updatedTransactions:方法中收到SKPaymentTransactionStateFailed,用户点击取消按钮后,例如没有互联网时.有什么方法可以区分这两种情况?
Ell*_*n S 18
这段代码适合我:
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"Other error");
} else {
NSLog(@"User canceled");
}
Run Code Online (Sandbox Code Playgroud)
Osc*_*car 14
艾伦的答案是完美的.以防有人想知道其他案件
switch (transaction.error.code) {
case SKErrorUnknown:
//Unknown error
break;
case SKErrorClientInvalid:
// client is not allowed to issue the request, etc.
break;
case SKErrorPaymentCancelled:
// user cancelled the request, etc.
break;
case SKErrorPaymentInvalid:
// purchase identifier was invalid, etc.
break;
case SKErrorPaymentNotAllowed:
// this device is not allowed to make the payment
break;
default:
break;
}
Run Code Online (Sandbox Code Playgroud)
这是Swift 3.0上的工作代码:
if let error = transaction.error as? NSError {
if error.domain == SKErrorDomain {
// handle all possible errors
switch (error.code) {
case SKError.unknown.rawValue:
print("Unknown error")
case SKError.clientInvalid.rawValue:
print("client is not allowed to issue the request")
case SKError.paymentCancelled.rawValue:
print("user cancelled the request")
case SKError.paymentInvalid.rawValue:
print("purchase identifier was invalid")
case SKError.paymentNotAllowed.rawValue:
print("this device is not allowed to make the payment")
default:
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 1
error检查设置的SKPaymentTransaction属性。
@property(非原子,只读) NSError *错误
描述处理事务时发生的错误的对象。(只读)
除非 transactionState 设置为 SKPaymentTransactionStateFailed,否则错误属性未定义。您的应用程序可以读取错误属性来确定事务失败的原因。
此外,您可能希望在启动交易之前使用 Apple 的 Reachability 类来确定互联网是否可用。
| 归档时间: |
|
| 查看次数: |
7374 次 |
| 最近记录: |