bizz84 / SwiftyStoreKit

Lightweight In App Purchases Swift framework for iOS 8.0+, tvOS 9.0+ and macOS 10.10+ ⛺
MIT License
6.57k stars 796 forks source link

Touch ID #104

Closed fatgue closed 7 years ago

fatgue commented 8 years ago

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)

                        }

                    }

                })`
bizz84 commented 8 years ago

@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.

fatgue commented 8 years ago

@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.

unittesting0 commented 7 years ago

@fatgue After the app gets approved in AppStore the touchID for in-app purchases will show up, don't worry!

bizz84 commented 7 years ago

Closing this as iOS handles this correctly for live apps. No custom touch ID code is required.

ios-nividata commented 6 years ago

@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.