Files
raspberry/iOS/Wallet/Sources/AppDelegate.swift
T

187 lines
7.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?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
configureUI()
IQKeyboardManager.shared.enable = true
FirebaseApp.configure()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
_ = Account.Service.History.shared
window?.tintColor = Asset.deepWater.color
if UserDefaults.standard.object(forKey: "dafaultCityId") == nil {
UserDefaults.standard.setValue(16 /* Moscow */, forKey: "dafaultCityId")
}
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 }
(self.window?.rootViewController as? MainController)?.process(deepLink: deepLink)
}
/*
guard let url = URL(string: Network.servers.current.malinkaGraphQL) else { return true }
let village = Village.create(city: url, street: Bundle.main.userAgent)
// Check Device
Task {
do {
let device = try await village.device()
print(">>>>>> \(device)")
let certified = try await village.attestate(device: device)
print(">>>>>> \(certified)")
} catch {
print(error)
}
}*/
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()
}
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 }
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)
})
})
} else {
AccountViewAuthorize.showGetPassword(in: controller, showPinBackButton: false, {
Accounts().migrateAccountIfNeeded(password: $0)
})
}
} else {
AccountViewAuthorize.showGetPassword(in: controller, showPinBackButton: false, {
Accounts().migrateAccountIfNeeded(password: $0)
})
}
}
}
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
}
}