|
|
@ -24,19 +24,15 @@ let server: Server = .uat2 |
|
|
|
var overlayView: UIView? |
|
|
|
|
|
|
|
@UIApplicationMain |
|
|
|
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate { |
|
|
|
class AppDelegate: UIResponder, UIApplicationDelegate { |
|
|
|
|
|
|
|
var window: UIWindow? |
|
|
|
let gcmMessageIDKey = "gcm_message_id" |
|
|
|
var firstTranscationStatusForHome:Bool? |
|
|
|
var firstTranscationStatusForProfileForm:Bool? |
|
|
|
|
|
|
|
var cmRegistrationId: String? |
|
|
|
|
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { |
|
|
|
func application( |
|
|
|
_ application: UIApplication, |
|
|
|
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? |
|
|
|
) -> Bool { |
|
|
|
UIApplication.shared.applicationIconBadgeNumber = 0 |
|
|
|
firstTranscationStatusForHome = true |
|
|
|
firstTranscationStatusForProfileForm = true |
|
|
|
|
|
|
|
NetworkActivityLogger.shared.startLogging() |
|
|
|
NetworkActivityLogger.shared.level = .debug |
|
|
@ -48,129 +44,48 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD |
|
|
|
|
|
|
|
Fabric.sharedSDK().debug = true |
|
|
|
Messaging.messaging().delegate = self |
|
|
|
registerForNotification(application: application) |
|
|
|
setUUID() |
|
|
|
setupNavBar() |
|
|
|
setupStatusBar() |
|
|
|
setEntryPoint() |
|
|
|
if #available(iOS 10.0, *) { |
|
|
|
UNUserNotificationCenter.current().delegate = self |
|
|
|
} else { |
|
|
|
// Fallback on earlier versions |
|
|
|
} |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
private func setUUID() { |
|
|
|
if UserDefaults.standard.string(forKey: AppConstants.uuid) == nil { |
|
|
|
let uuid = UUID().uuidString |
|
|
|
UserDefaults.standard.set(uuid, forKey: AppConstants.uuid) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private func setupStatusBar() { |
|
|
|
// let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView |
|
|
|
// if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) { |
|
|
|
// statusBar.backgroundColor = UIColor.blue |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
private func setupNavBar() { |
|
|
|
let appearance = UINavigationBar.appearance() |
|
|
|
appearance.backIndicatorImage = #imageLiteral(resourceName: "backIconBlack") |
|
|
|
appearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "backIconBlack") |
|
|
|
appearance.tintColor = UIColor.black |
|
|
|
} |
|
|
|
|
|
|
|
private func setEntryPoint() { |
|
|
|
|
|
|
|
// check user status |
|
|
|
|
|
|
|
guard let _ = KeyChain.shared.get(key: .email), |
|
|
|
(KeyChain.shared.get(key: .login) ?? "1") == "1" ? true : false else { |
|
|
|
self.goSplashScreen() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
let biometricAuthenticationWireframe = BiometricAuthenticationWireframe() |
|
|
|
biometricAuthenticationWireframe.openWithDelegate( |
|
|
|
on: self.window!, |
|
|
|
delegate: self |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
private func registerForNotification(application: UIApplication) { |
|
|
|
|
|
|
|
let settings: UIUserNotificationSettings = |
|
|
|
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) |
|
|
|
let center = UNUserNotificationCenter.current() |
|
|
|
center.delegate = self |
|
|
|
center.requestAuthorization(options: [.alert, .sound, .badge]) { (_, _) in} |
|
|
|
application.registerForRemoteNotifications() |
|
|
|
application.registerUserNotificationSettings(settings) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { |
|
|
|
|
|
|
|
if userInfo[gcmMessageIDKey] != nil { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], |
|
|
|
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) { |
|
|
|
cmRegistrationId = fcmToken |
|
|
|
|
|
|
|
print(fcmToken) |
|
|
|
} |
|
|
|
print("FCM Token: \(Messaging.messaging().fcmToken ?? "nil")") |
|
|
|
|
|
|
|
setUUID() |
|
|
|
setupNavBar() |
|
|
|
setEntryPoint() |
|
|
|
|
|
|
|
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) { |
|
|
|
print(remoteMessage.appData) |
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
public func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) { |
|
|
|
func application( |
|
|
|
_ application: UIApplication, |
|
|
|
didReceiveRemoteNotification userInfo: [AnyHashable: Any] |
|
|
|
) { } |
|
|
|
|
|
|
|
} |
|
|
|
func application( |
|
|
|
_ application: UIApplication, |
|
|
|
didReceiveRemoteNotification userInfo: [AnyHashable: Any], |
|
|
|
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void |
|
|
|
) { } |
|
|
|
|
|
|
|
@available(iOS 10.0, *) |
|
|
|
func userNotificationCenter(_ center: UNUserNotificationCenter, |
|
|
|
willPresent notification: UNNotification, |
|
|
|
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { |
|
|
|
// var userInfo = notification.request.content.userInfo |
|
|
|
|
|
|
|
// if let aps = userInfo["aps"] as? NSDictionary, |
|
|
|
// let alert = aps["alert"] as? NSDictionary, |
|
|
|
// let body = alert["body"] as? String, |
|
|
|
// let title = alert["title"] as? String { |
|
|
|
// let image = UIImage.init(named: "ic_gme") |
|
|
|
// let banner = Banner(title: title, subtitle: body, image: image, backgroundColor: UIColor(red:0.93, green:0.11, blue:0.14, alpha:1.0)) |
|
|
|
// banner.show(duration: 5.0) |
|
|
|
// } |
|
|
|
completionHandler( |
|
|
|
[UNNotificationPresentationOptions.alert, |
|
|
|
UNNotificationPresentationOptions.sound, |
|
|
|
UNNotificationPresentationOptions.badge]) |
|
|
|
} |
|
|
|
func application( |
|
|
|
_ application: UIApplication, |
|
|
|
didFailToRegisterForRemoteNotificationsWithError error: Error |
|
|
|
) { } |
|
|
|
|
|
|
|
|
|
|
|
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { |
|
|
|
// print("Unable to register for remote notifications: \(error.localizedDescription)") |
|
|
|
} |
|
|
|
|
|
|
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { |
|
|
|
func application( |
|
|
|
_ application: UIApplication, |
|
|
|
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data |
|
|
|
) { |
|
|
|
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)}) |
|
|
|
print("APNs device token: \(deviceTokenString)") |
|
|
|
|
|
|
|
Messaging.messaging().apnsToken = deviceToken |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
method for redirection of page when push notification tap |
|
|
|
*/ |
|
|
|
|
|
|
|
func applicationDidEnterBackground(_ application: UIApplication) { |
|
|
|
let store = UserDefaults.standard |
|
|
|
let language = Localize.currentLanguage() |
|
|
@ -197,6 +112,39 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD |
|
|
|
overlayView?.removeFromSuperview() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - Other Functions |
|
|
|
extension AppDelegate { |
|
|
|
private func setUUID() { |
|
|
|
if UserDefaults.standard.string(forKey: AppConstants.uuid) == nil { |
|
|
|
let uuid = UUID().uuidString |
|
|
|
UserDefaults.standard.set(uuid, forKey: AppConstants.uuid) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private func setupNavBar() { |
|
|
|
let appearance = UINavigationBar.appearance() |
|
|
|
appearance.backIndicatorImage = #imageLiteral(resourceName: "backIconBlack") |
|
|
|
appearance.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "backIconBlack") |
|
|
|
appearance.tintColor = UIColor.black |
|
|
|
} |
|
|
|
|
|
|
|
private func setEntryPoint() { |
|
|
|
guard let _ = KeyChain.shared.get(key: .email), |
|
|
|
(KeyChain.shared.get(key: .login) ?? "1") == "1" ? true : false else { |
|
|
|
self.goSplashScreen() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
let biometricAuthenticationWireframe = BiometricAuthenticationWireframe() |
|
|
|
biometricAuthenticationWireframe.openWithDelegate( |
|
|
|
on: self.window!, |
|
|
|
delegate: self |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
private func doLogin(){ |
|
|
|
self.window?.rootViewController?.showProgressHud() |
|
|
|
|
|
|
@ -254,11 +202,60 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - UNUserNotificationCenterDelegate |
|
|
|
extension AppDelegate: UNUserNotificationCenterDelegate { |
|
|
|
func userNotificationCenter( |
|
|
|
_ center: UNUserNotificationCenter, |
|
|
|
willPresent notification: UNNotification, |
|
|
|
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void |
|
|
|
) { |
|
|
|
let userInfo = notification.request.content.userInfo |
|
|
|
print("Message ID: \(userInfo["gcm_message_id"] ?? "nil")") |
|
|
|
|
|
|
|
completionHandler([ |
|
|
|
UNNotificationPresentationOptions.alert, |
|
|
|
UNNotificationPresentationOptions.sound, |
|
|
|
UNNotificationPresentationOptions.badge |
|
|
|
]) |
|
|
|
} |
|
|
|
|
|
|
|
func userNotificationCenter( |
|
|
|
_ center: UNUserNotificationCenter, |
|
|
|
didReceive response: UNNotificationResponse, |
|
|
|
withCompletionHandler completionHandler: @escaping () -> Void |
|
|
|
) { |
|
|
|
let userInfo = response.notification.request.content.userInfo |
|
|
|
print("Message ID: \(userInfo["gcm_message_id"] ?? "nil")") |
|
|
|
|
|
|
|
print(userInfo) |
|
|
|
completionHandler() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - MessagingDelegate |
|
|
|
extension AppDelegate: MessagingDelegate { |
|
|
|
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) { |
|
|
|
print("Firebase registration token: \(fcmToken)") |
|
|
|
|
|
|
|
let userInfo = ["token": fcmToken] |
|
|
|
NotificationCenter.default.post( |
|
|
|
name: Notification.Name("FCMToken"), |
|
|
|
object: nil, |
|
|
|
userInfo: userInfo |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) { |
|
|
|
print("Received data message: \(remoteMessage.appData)") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - BiometricAuthenticationViewControllerDelegate |
|
|
|
extension AppDelegate: BiometricAuthenticationViewControllerDelegate{ |
|
|
|
func viewController(_ viewController: BiometricAuthenticationViewController, informationTitleLabel titleLabel: UILabel) { |
|
|
|
func viewController( |
|
|
|
_ viewController: BiometricAuthenticationViewController, |
|
|
|
informationTitleLabel titleLabel: UILabel |
|
|
|
) { |
|
|
|
titleLabel.text = "bio_login_intro_text".localized() |
|
|
|
} |
|
|
|
|
|
|
@ -266,7 +263,11 @@ extension AppDelegate: BiometricAuthenticationViewControllerDelegate{ |
|
|
|
self.doLogin() |
|
|
|
} |
|
|
|
|
|
|
|
func viewController(_ viewController: BiometricAuthenticationViewController, didFailWithError error: Error, errorMessage: String?) { |
|
|
|
func viewController( |
|
|
|
_ viewController: BiometricAuthenticationViewController, |
|
|
|
didFailWithError error: Error, |
|
|
|
errorMessage: String? |
|
|
|
) { |
|
|
|
print("BiometricAuthenticationWireframe Error: \(errorMessage ?? "")") |
|
|
|
|
|
|
|
// if don't use biometric authentication or user press password |
|
|
@ -290,13 +291,11 @@ extension AppDelegate: BiometricAuthenticationViewControllerDelegate{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func doSelectLocalAuthenticationPolicy(_ viewController: BiometricAuthenticationViewController) -> BiometricAuthenticationPolicy{ |
|
|
|
func doSelectLocalAuthenticationPolicy(_ viewController: BiometricAuthenticationViewController) -> BiometricAuthenticationPolicy { |
|
|
|
return .deviceOwnerAuthenticationWithBiometrics |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - SecureKeypadDelegate |
|
|
|
extension AppDelegate: SecureKeypadDelegate { |
|
|
|
func didComplete(_ encryptedString: String) { |
|
|
|