231 lines
9.3 KiB
Swift
231 lines
9.3 KiB
Swift
//
|
|
// AppDelegate.swift
|
|
// List
|
|
//
|
|
// Created by Igor Danich on 25.06.2020.
|
|
// Copyright © 2020 Igor Danich. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import CoreData
|
|
import IQKeyboardManagerSwift
|
|
import Firebase
|
|
import FirebaseMessaging
|
|
import Branch
|
|
import WalletKit
|
|
|
|
@UIApplicationMain
|
|
final class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
|
var window: UIWindow?
|
|
private var deepLink: DeepLink?
|
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
|
|
self.configureUI()
|
|
|
|
IQKeyboardManager.shared.enable = true
|
|
|
|
FirebaseApp.configure()
|
|
|
|
Messaging.messaging().delegate = self
|
|
|
|
UNUserNotificationCenter.current().delegate = self
|
|
|
|
_ = Account.Service.History.shared
|
|
self.window?.tintColor = Asset.deepWater.color
|
|
|
|
if UserDefaults.standard.object(forKey: "dafaultCityId") == nil {
|
|
UserDefaults.standard.setValue(16 /* Moscow */, forKey: "dafaultCityId")
|
|
}
|
|
|
|
// PAYCASH-NEW
|
|
if UserDefaults.standard.string(forKey: "someUUID").orCreate("").isEmpty {
|
|
UserDefaults.standard.setValue(UUID().uuidString, forKey: "someUUID")
|
|
}
|
|
|
|
Cards.Service() // This line will migrate old Bank cards to new format
|
|
|
|
AccountOnboarding.Service.IAP.shared.startObserving()
|
|
AccountOnboarding.Service.IAP.shared.getProducts()
|
|
|
|
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
|
|
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { _, _ in }
|
|
application.registerForRemoteNotifications()
|
|
|
|
StoreReviewHelper.incrementAppOpenedCount()
|
|
|
|
Branch.getInstance().initSession(launchOptions: launchOptions) { [unowned self] (params, _) in
|
|
guard let deepLink = DeepLink.create(params: params) else { return }
|
|
if Account.Service.Authorize.shared.password != nil {
|
|
(self.window?.rootViewController as? MainController)?.process(deepLink: deepLink)
|
|
} else {
|
|
self.deepLink = deepLink
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
private func configureUI() {
|
|
UIActivityIndicatorView.appearance().color = Asset.deepWater.color
|
|
UINavigationBar.appearance().shadowImage = UIImage()
|
|
UINavigationBar.appearance().barTintColor = .white
|
|
UINavigationBar.appearance().tintColor = #colorLiteral(red: 0.282, green: 0.322, blue: 0.3803921569, alpha: 1)
|
|
UINavigationBar.appearance().isTranslucent = false
|
|
UINavigationBar.appearance().titleTextAttributes = [
|
|
.font: UIFont.font(style: .medium, size: 20),
|
|
.foregroundColor: Asset.textCoal.color
|
|
]
|
|
UIActivityIndicatorView.appearance().color = Asset.deepWater.color
|
|
UISegmentedControl.appearance().setTitleTextAttributes([
|
|
.font: UIFont.font(style: .medium, size: 14),
|
|
.foregroundColor: Asset.textGranite.color
|
|
], for: .normal)
|
|
if #available(iOS 13, *) {
|
|
UISegmentedControl.appearance().setTitleTextAttributes([
|
|
.font: UIFont.font(style: .medium, size: 14),
|
|
.foregroundColor: Asset.textSnow.color
|
|
], for: .selected)
|
|
UISegmentedControl.appearance().selectedSegmentTintColor = Asset.deepWater.color
|
|
}
|
|
UITabBar.appearance().tintColor = Asset.deepWater.color
|
|
UITabBarItem.appearance().setTitleTextAttributes([
|
|
.font: UIFont.font(style: .medium, size: 12)
|
|
], for: .normal)
|
|
UISwitch.appearance().onTintColor = Asset.deepWater.color
|
|
|
|
}
|
|
|
|
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
|
|
|
|
func applicationWillResignActive(_ application: UIApplication) {
|
|
blurView.frame = window?.bounds ?? .zero
|
|
blurView.alpha = 0
|
|
window?.addSubview(blurView)
|
|
UIView.animate(withDuration: Animation.slow) { self.blurView.alpha = 1 }
|
|
Account.Service.Authorize.shared.saveUptime()
|
|
}
|
|
|
|
private func showEnvironmentAlert(_ completion: @escaping () -> Void) {
|
|
|
|
let current = ApplicationEnvironment.shared().current
|
|
if current.paycash.name != ApplicationEnvironment.PayCashEnvironment.production.rawValue
|
|
|| current.malinka.name != ApplicationEnvironment.MalinkaEnvironment.production.rawValue {
|
|
|
|
let alert = UIAlertController(title: "Environments",
|
|
message: "Malinka: \(current.malinka.name)\nPaycash: \(current.paycash.name)",
|
|
preferredStyle: .alert)
|
|
|
|
alert.addAction(UIAlertAction(title: "Ok",
|
|
style: .destructive,
|
|
handler: {(_: UIAlertAction!) in
|
|
alert.dismiss(animated: true)
|
|
completion()
|
|
}))
|
|
|
|
self.window?.rootViewController?.present(alert, animated: true)
|
|
} else {
|
|
completion()
|
|
}
|
|
}
|
|
|
|
|
|
func applicationDidBecomeActive(_ application: UIApplication) {
|
|
UIView.animate(withDuration: Animation.slow) {
|
|
self.blurView.alpha = 0
|
|
} completion: { _ in
|
|
self.blurView.removeFromSuperview()
|
|
}
|
|
Account.Service.Authorize.shared.clearUptime()
|
|
if let controller = window?.rootViewController,
|
|
Accounts().isPasswordExists,
|
|
UserDefaults.standard.bool(forKey: "isPinPwdMode") {
|
|
guard !((controller.presentedViewController as? UINavigationController)?.topViewController is AccountControllerPin) else { return }
|
|
guard !(controller.presentedViewController is AccountControllerPin) else { return }
|
|
guard !((controller.presentedViewController?.presentedViewController as? UINavigationController)?.topViewController is AccountControllerPin) else { return }
|
|
|
|
self.showEnvironmentAlert { [weak self] in
|
|
|
|
guard let self = self else { return }
|
|
|
|
if (Account.Service.Authorize.shared.password ?? "").isEmpty {
|
|
if controller.presentedViewController != nil {
|
|
controller.dismiss(animated: false, completion: {
|
|
AccountViewAuthorize.showGetPassword(in: controller, showPinBackButton: false, {
|
|
Accounts().migrateAccountIfNeeded(password: $0)
|
|
if let deepLink = self.deepLink {
|
|
self.deepLink = nil
|
|
(self.window?.rootViewController as? MainController)?.process(deepLink: deepLink)
|
|
}
|
|
})
|
|
})
|
|
} else {
|
|
AccountViewAuthorize.showGetPassword(in: controller, showPinBackButton: false, {
|
|
Accounts().migrateAccountIfNeeded(password: $0)
|
|
if let deepLink = self.deepLink {
|
|
self.deepLink = nil
|
|
(self.window?.rootViewController as? MainController)?.process(deepLink: deepLink)
|
|
}
|
|
})
|
|
}
|
|
} else {
|
|
AccountViewAuthorize.showGetPassword(in: controller, showPinBackButton: false, {
|
|
Accounts().migrateAccountIfNeeded(password: $0)
|
|
if let deepLink = self.deepLink {
|
|
self.deepLink = nil
|
|
(self.window?.rootViewController as? MainController)?.process(deepLink: deepLink)
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
func application(
|
|
_ application: UIApplication,
|
|
continue userActivity: NSUserActivity,
|
|
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
|
|
) -> Bool {
|
|
Branch.getInstance().continue(userActivity)
|
|
}
|
|
|
|
func application(
|
|
_ app: UIApplication,
|
|
open url: URL,
|
|
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
|
|
) -> Bool {
|
|
Branch.getInstance().application(app, open: url, options: options)
|
|
}
|
|
|
|
func application(
|
|
_ application: UIApplication,
|
|
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
|
|
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
|
|
) {
|
|
Branch.getInstance().handlePushNotification(userInfo)
|
|
guard UIApplication.shared.applicationState != .active else { return }
|
|
|
|
guard let deepLink = DeepLink.create(info: userInfo) else { return }
|
|
(self.window?.rootViewController as? MainController)?.process(deepLink: deepLink)
|
|
}
|
|
|
|
func applicationWillTerminate(_ application: UIApplication) {
|
|
AccountOnboarding.Service.IAP.shared.stopObserving()
|
|
}
|
|
}
|
|
|
|
extension AppDelegate: UNUserNotificationCenterDelegate {
|
|
|
|
}
|
|
|
|
extension AppDelegate: MessagingDelegate {
|
|
|
|
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
|
|
Accounts().isPushEnabled = true
|
|
}
|
|
|
|
}
|