Sorry, unavailability of iPhone-X.
After the launch of iPhone-X, everyone wants their application should be compatible with iOS11 and with touchID but the problem is it's too expensive for a developer to test touch ID.
I don't have iPhone to check my code but can I check the same in iOS simulator?
let context = LAContext()
if ( context.biometryType == .typeFaceID ) {
// Face ID
}
if ( context.biometryType == .typeTouchID) {
// Touch ID
} else {
// Stone Age
}
You can test it without device also. Use simulator's Face ID to validate your code and it will behave similarly in iPhone-X also.
Simulator does not recognise a face but allows you to simulate a matching and non-matching faces, if you've enabled Enrolled option from Face ID.
Add following code to your view controller and try with Face-ID
import LocalAuthentication
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
localAuthentication()
}
func localAuthentication() -> Void {
let laContext = LAContext()
var error: NSError?
let biometricsPolicy = LAPolicy.deviceOwnerAuthenticationWithBiometrics
if (laContext.canEvaluatePolicy(biometricsPolicy, error: &error)) {
if let laError = error {
print("laError - \(laError)")
return
}
var localizedReason = "Unlock device"
if #available(iOS 11.0, *) {
if (laContext.biometryType == LABiometryType.faceID) {
localizedReason = "Unlock using Face ID"
print("FaceId support")
} else if (laContext.biometryType == LABiometryType.touchID) {
localizedReason = "Unlock using Touch ID"
print("TouchId support")
} else {
print("No Biometric support")
}
} else {
// Fallback on earlier versions
}
laContext.evaluatePolicy(biometricsPolicy, localizedReason: localizedReason, reply: { (isSuccess, error) in
DispatchQueue.main.async(execute: {
if let laError = error {
print("laError - \(laError)")
} else {
if isSuccess {
print("sucess")
} else {
print("failure")
}
}
})
})
}
}
}
FaceID authentication will prompt you for first time to allow FaceID detection for your app.
Now enable Face ID enrolment and run your app to test Face ID simulation Testing.
Here is simulation result for matching and non-matching faces.
Result for matching face:
Result for non-matching face:
Related
I am trying to Unsubscribe subscriptions APNS & APNS.VOIP on logout in iOS swift Quickblox project. It unsubscribes only one of them can anyone please guide me.
Here's my code for logout.
#objc func didTapLogout(_ sender: UIBarButtonItem) {
if QBChat.instance.isConnected == false {
SVProgressHUD.showError(withStatus: "Error")
return
}
SVProgressHUD.show(withStatus: "SA_STR_LOGOUTING".localized)
SVProgressHUD.setDefaultMaskType(.clear)
guard let identifierForVendor = UIDevice.current.identifierForVendor else {
return
}
let uuidString = identifierForVendor.uuidString
#if targetEnvironment(simulator)
disconnectUser()
#else
QBRequest.subscriptions(successBlock: { (response, subscriptions) in
if let subscriptions = subscriptions {
for subscription in subscriptions {
if let subscriptionsUIUD = subscriptions.first?.deviceUDID,
subscriptionsUIUD == uuidString,
subscription.notificationChannel == .APNS {
self.unregisterSubscription(forUniqueDeviceIdentifier: uuidString)
return
}
}
}
self.disconnectUser()
}) { response in
if response.status.rawValue == 404 {
self.disconnectUser()
}
}
#endif
}
private func unregisterSubscription(forUniqueDeviceIdentifier uuidString: String) {
QBRequest.unregisterSubscription(forUniqueDeviceIdentifier: uuidString, successBlock: { response in
self.disconnectUser()
}, errorBlock: { error in
if let error = error.error {
SVProgressHUD.showError(withStatus: error.localizedDescription)
return
}
SVProgressHUD.dismiss()
})
}
Environment details
Info Value
iOS Version 13.0
Quickblox iOS SDK version 2.17.4
QuickbloxWebRTC SDK version 2.7.4
Xcode Version e.g. Xcode 12.0
Make sure you are connected to chat when removing subscriptions and logout only when all unsubscribe completions are called. You can also simply unsubscribe from remote notifications and PushKit in the app.
I have developed my game in Godot game engine and I'm now trying to implement googles gdpr consent form into my Xcode project.
I am using Xcode 11.5
The code below is my current code which does not result in the consent form popping up.
It might be something with the class I made but I'm not sure how that works.
import UIKit
import PersonalizedAdConsent
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
PACConsentInformation.sharedInstance.requestConsentInfoUpdate(
forPublisherIdentifiers: ["I have the id just not posted here"])
{(_ error: Error?) -> Void in
if let error = error {
// Consent info update failed.
} else {
// Consent info update succeeded. The shared PACConsentInformation
// instance has been updated.
}
}
guard let privacyUrl = URL(string: "My_privacy_policy(not_actual)"),
let form = PACConsentForm(applicationPrivacyPolicyURL: privacyUrl) else {
print("incorrect privacy URL.")
return
}
form.shouldOfferPersonalizedAds = true
form.shouldOfferNonPersonalizedAds = true
form.shouldOfferAdFree = false
form.load {(_ error: Error?) -> Void in
print("Load complete.")
if let error = error {
// Handle error.
print("Error loading form: \(error.localizedDescription)")
} else {
// Load successful.
}
}
//Finally present the consent form
form.present(from: self) { (error, userPrefersAdFree) in
if let error = error {
// Handle error.
} else if userPrefersAdFree {
// User prefers to use a paid version of the app.
} else {
// Check the user's consent choice.
let status =
PACConsentInformation.sharedInstance.consentStatus
}
}
}
}
Any help is appreciated :)
protocol Device {
}
protocol ActiveDevice: Device {
}
protocol NoActive: Device {
}
ViewController:
class ViewController : UIViewController {
let device: Device
}
Setting device for ViewController. currentDevice is an object which conforms to protocol Device
vc.device = currentDevice as! ActiveDevice
Checking if it conforms to the protocol:
if let currentDevice = device as? NoActive {
print("Its not active device")
}else if let currentDevice = device as? ActiveDevice {
print("Its active device")
}else {
print("Its just a device")
}
It always prints Its not active device what I would expect in this case that it would print Its active device
Please check the following code and let me know if this helps.
protocol Device {
}
protocol ActiveDevice: Device {
}
protocol NoActive: Device {
}
// class TestDevice: Device {
// class TestDevice: ActiveDevice {
class TestDevice: NoActive {
}
let currentDevice = TestDevice()
// let device: Device = currentDevice as! ActiveDevice
(It threw error as "Could not cast value of type '__lldb_expr_9.TestDevice' (0x11a2f9090) to '__lldb_expr_9.ActiveDevice' (0x11a6d0628)."). We cannot do this.
let device: Device = currentDevice
if device is NoActive {
print("Its not active device")
}else if device is ActiveDevice {
print("Its active device")
}else {
print("Its just a device")
}
Now, the output is "Its not active device". And after changing the TestDevice to "ActiveDevice", it printed "Its active device" and so on.
I was using NSFaceIDUsageDescription in my app and it was working. I deleted my app from my device and and re-uploaded (plugging my device into my mac and running from xcode) it and now I don't get the alert that my app would like to use FaceID, how come the alert is not appearing anymore? This is preventing me from using FaceID in my app.
class TouchIDAuth {
let context = LAContext()
func canEvaluatePolicy() -> Bool {
return context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
}
func authenticateUser(completion: #escaping (NSNumber?) -> Void) {
guard canEvaluatePolicy() else {
completion(0)
return
}
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Logging in with Touch ID") { (success, evaluateError) in
if success {
DispatchQueue.main.async {
completion(nil)
}
} else {
let response: NSNumber
switch evaluateError?._code {
case Int(kLAErrorAuthenticationFailed):
response = 2
case Int(kLAErrorUserCancel):
response = 3
case Int(kLAErrorUserFallback):
response = 4
default:
response = 1
}
completion(response)
}
}
}
}
And when I do this:
let touchMe = TouchIDAuth()
print(touchMe.canEvaluatePolicy())
The print returns false.
Is this an issue with my device? Or with NSFaceIDUsageDescription?
When your device exceeds the limit of incorrect attempts it usually returns false.
Try locking your device, then unlocking with face/touch ID and it starts working again in your app.
It should also return an error code why it is failling for evaluateError
Hope this was your case and solves the issue.
I'm using Xcode 7.2 with HomeKit Accessory Simulator Version 1.3 (77.1)
I have the following code in my HomeKit code
//MARK: UITableViewDelegate
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let accessory = accessories[indexPath.row] as HMAccessory
if let room = homeManager.primaryHome?.rooms.first as HMRoom? {
homeManager.primaryHome?.addAccessory(accessory, completionHandler: { (error) -> Void in
if error != nil {
print("Issues adding accessory to home. \(error?.localizedDescription)")
} else {
self.homeManager.primaryHome?.assignAccessory(accessory, toRoom: room, completionHandler: { (error) -> Void in
if error != nil {
print("Issues adding accessory to room. \(error?.localizedDescription)")
} else {
self.navigationController?.popViewControllerAnimated(true)
}
})
}
})
}
}
When I click on the UITableViewCell, it brings up the Add Accessory dialog and after I enter the pairing / setup code, it gives me the error :
Issues adding accessory to home. Optional("Operation in progress.")
At other times I get
Issues adding accessory to home. Optional("Client request error when
communicating with accessory.")
When I run the same code on iPhone (iOS 9.2.1) I get the following error
Something went wrong when attempting to create our home.
Optional("Cloud data sync is in progress.")
Is this is a known issue in HomeKit? Or is it a bug in the HomeKit Hardware Simulator? Is there a workaround / fix?
You probably have to change
if let room = homeManager.primaryHome?.rooms.first as HMRoom? {
to
if let room = homeManager.primaryHome?.rooms.first as? HMRoom {
if I'm reading this code correctly?
But it would be more readable - and debuggable - if the conditions were separated and if you used the unwrapped object. Assuming HMRoom is a class:
if let home = homeManager.primaryHome,
room = home.rooms.first as? HMRoom {
home.addAccessory(accessory, completionHandler: { (error) -> Void in
if error != nil {
print("Issues adding accessory to home. \(error?.localizedDescription)")
} else {
home.assignAccessory(accessory, toRoom: room, completionHandler: { (error) -> Void in
if error != nil {
print("Issues adding accessory to room. \(error?.localizedDescription)")
} else {
self.navigationController?.popViewControllerAnimated(true)
}
})
}
})
}