204 lines
7.1 KiB
Swift
204 lines
7.1 KiB
Swift
//
|
|
// AppDelegate.swift
|
|
// List
|
|
//
|
|
// Created by Igor Danich on 25.06.2020.
|
|
// Copyright © 2020 Igor Danich. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import IQKeyboardManagerSwift
|
|
import Firebase
|
|
import FirebaseMessaging
|
|
import Branch
|
|
import WalletFoundation
|
|
import WalletKit
|
|
import Combine
|
|
|
|
|
|
@UIApplicationMain
|
|
final class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
|
var window: UIWindow?
|
|
private var deepLink: DeepLink?
|
|
private lazy var firebaseService = FirebasePushTokenService(tokenLifetime: ApplicationEnvironment.shared().current.firebaseTokenLifetime)
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
|
|
self.configureUI()
|
|
|
|
IQKeyboardManager.shared.enable = true
|
|
|
|
let window = UIWindow(frame: UIScreen.main.bounds)
|
|
window.tintColor = Asset.deepWater.color
|
|
|
|
self.window = window
|
|
|
|
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()
|
|
|
|
StoreReviewHelper.incrementAppOpenedCount()
|
|
|
|
Branch.getInstance().initSession(launchOptions: launchOptions) { [weak self] (params, _) in
|
|
guard let self,
|
|
let deepLink = DeepLink.create(params: params) else { return }
|
|
if Account.Service.Authorize.shared.password.isExist,
|
|
let controller = self.window?.rootViewController as? MainController {
|
|
controller.process(deepLink: deepLink)
|
|
} else {
|
|
self.deepLink = deepLink
|
|
}
|
|
}
|
|
|
|
let controller = OnBoardingWalletController()
|
|
window.rootViewController = controller
|
|
window.makeKeyAndVisible()
|
|
|
|
DispatchQueue.main.async {
|
|
controller.showPin {
|
|
DispatchQueue.main.async { [weak self] in
|
|
self?.switchMainController(application: application)
|
|
}
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
private func switchMainController(application: UIApplication) {
|
|
|
|
self.firebaseService.$token.sink { fcmToken in
|
|
fcmToken >>- { Accounts().updatePush(token: $0) }
|
|
}
|
|
.store(in: &self.cancellables)
|
|
|
|
UNUserNotificationCenter.current().delegate = self
|
|
|
|
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
|
|
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { _, _ in }
|
|
application.registerForRemoteNotifications()
|
|
|
|
let controller = StoryboardScene.Main.initialScene.instantiate()
|
|
self.window?.rootViewController = controller
|
|
|
|
if let deepLink = self.deepLink {
|
|
self.deepLink = nil
|
|
controller.process(deepLink: deepLink)
|
|
}
|
|
}
|
|
|
|
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()
|
|
}
|
|
|
|
func applicationDidBecomeActive(_ application: UIApplication) {
|
|
|
|
UIView.animate(withDuration: Animation.slow) {
|
|
self.blurView.alpha = 0
|
|
} completion: { _ in
|
|
self.blurView.removeFromSuperview()
|
|
}
|
|
|
|
Account.Service.Authorize.shared.clearUptime()
|
|
}
|
|
|
|
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 }
|
|
if let mainController = self.window?.rootViewController as? MainController {
|
|
mainController.process(deepLink: deepLink)
|
|
} else {
|
|
self.deepLink = deepLink
|
|
}
|
|
}
|
|
|
|
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
self.firebaseService.updateAPNS(token: deviceToken)
|
|
}
|
|
|
|
func applicationWillTerminate(_ application: UIApplication) {
|
|
AccountOnboarding.Service.IAP.shared.stopObserving()
|
|
}
|
|
}
|
|
|
|
extension AppDelegate: UNUserNotificationCenterDelegate {
|
|
|
|
}
|