How can i use Touch ID with SwiftyStoreKit? For example if i want make in app purchase. I am new in TouchID and inApp purchases.
`let authenticationContext = LAContext()
var error:NSError?
guard authenticationContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
self.showAlertViewIfNoBiometricSensorHasBeenDetected()
return
}
authenticationContext.evaluatePolicy(
.deviceOwnerAuthenticationWithBiometrics,
localizedReason: "TouchID",
reply: { [unowned self] (success, error) -> Void in
if( success ) {
// Fingerprint recognized
SwiftyStoreKit.purchaseProduct(self.AppBundleId + "." + RegisteredPurchase.InstagramPurchase.rawValue) { result in
indicator.startAnimating()
switch result {
case .success(let productId):
if productId == pro1 {
}
if productId == pro2 {
}
indicator.stopAnimating()
case .error(let error):
print("Purchase Failed: \(error)")
switch error {
case .failed(let error):
if error._domain == SKErrorDomain {
self.alertWithTitle("Purchase failed", message: "Please check your Internet connection or try again later")
}
self.alertWithTitle("Purchase failed", message: "Unknown error. Please contact support")
case .invalidProductId(let productId):
self.alertWithTitle("Purchase failed", message: "\(productId) is not a valid product identifier")
case .noProductIdentifier:
self.alertWithTitle("Purchase failed", message: "Product not found")
case .paymentNotAllowed:
self.alertWithTitle("Payments not enabled", message: "You are not allowed to make payments")
}
indicator.stopAnimating()
}
indicator.stopAnimating()
}
}else {
// Check if there is an error
if let error = error {
print(error.localizedDescription)
}
}
})`
@fatgue you don't need to write any code to use Touch ID. This is provided automatically as long as you have a device with Touch ID.
@bizz84 thanks for your answer. I have an Iphone 6s and if i make a IAP the Touch ID doesn't show up. I will only asked for my iTunes password.
@fatgue After the app gets approved in AppStore the touchID for in-app purchases will show up, don't worry!
Closing this as iOS handles this correctly for live apps. No custom touch ID code is required.
@bizz84 I still have a problem of touch id. The user needs to add touch id as well as iTunes password both while in-app in app store build.
Most helpful comment
@fatgue After the app gets approved in AppStore the touchID for in-app purchases will show up, don't worry!