Я новичок в iOS Swift.Я добавил функцию LocalAuthentication (TouchID) в свое приложение.Когда сенсорный идентификатор включен, я перенаправляю пользователя на страницу Dashboard, при успешной аутентификации.Теперь, когда получено push-уведомление, если это блог типа категории, я хочу открыть страницу блога, если это выплаты типа категории, я хочу открыть страницу выплат, и если это новость, я хочу открыть страницу уведомления.Но из-за сенсорного идентификатора включен, я перенаправляю на страницу Dashboard, а не на определенный ViewController при получении уведомления.Не понимаю, как справиться с этим сценарием.
Что я делаю, когда получаю уведомление:
func navigateToView (userInfo: [AnyHashable: Any]) {
print("CLICKCATEGORY \(category)")
if(category == "payout_alerts"){ // if notification is payout alert open payout alerts controller
// post a notification
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "openPayoutAlerts"), object: nil)
}else if(category == "blog"){ // if notification is blogs alert open blogs controller
print("OPENING BLOGS")
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "OpenBlogs"), object: nil)
}else if(category == "chat"){ // if notification is mypost alert open My post controller
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "openMypostContoller"), object: nil)
}else if(category == "notification"){ // if notification is ingeneral notification open notification controller
let notificationobj = NotificationObj(userid: userid, notificationType: type, title:title, body:body, link:image, image_url:category, read_status:"1")
notificationLists.append(notificationobj)
saveNewNotificationInBackground(userInfo: userInfo)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "openNotifications"), object: nil)
}
}
Моя функция аутентификации выглядит следующим образом:
func authenticationWithTouchID() {
let localAuthenticationContext = LAContext()
localAuthenticationContext.localizedFallbackTitle = "Enter Passcode"
var _: AppDelegate? = (UIApplication.shared.delegate as? AppDelegate)
let backgrView = UIView(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(UIScreen.main.bounds.size.width), height: CGFloat(UIScreen.main.bounds.size.height)))
backgrView.backgroundColor = UIColor.black
//backgrView.alpha = 0.9
window?.addSubview(backgrView)
let blurEffect = UIBlurEffect(style: .light)
let blurVisualEffectView = UIVisualEffectView(effect: blurEffect)
blurVisualEffectView.frame = backgrView.bounds
backgrView.addSubview(blurVisualEffectView)
var authError: NSError?
let reasonString = "Please authenticate to use App"
if localAuthenticationContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &authError) {
localAuthenticationContext.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reasonString) { success, evaluateError in
if success {
DispatchQueue.main.async
{
blurVisualEffectView.removeFromSuperview()
print("Authentication success by the system")
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "Dashboard") as UIViewController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()
}
} else {
//TODO: User did not authenticate successfully, look at error and take appropriate action
guard let error = evaluateError else {
return
}
print(self.evaluateAuthenticationPolicyMessageForLA(errorCode: error._code))
//TODO: If you have choosen the 'Fallback authentication mechanism selected' (LAError.userFallback). Handle gracefully
}
}
} else {
guard let error = authError else {
return
}
//TODO: Show appropriate alert if biometry/TouchID/FaceID is lockout or not enrolled
print("APP LOCKED : \(self.evaluatePolicyFailErrorMessageForLA(errorCode: error.code))")
}
}