Caps-iOS/CapCollector/AppDelegate.swift
Christoph Hagen 2806733b71 Version 1
2019-03-15 13:19:19 +01:00

95 lines
3.0 KiB
Swift

//
// AppDelegate.swift
// CapFinder
//
// Created by User on 31.01.18.
// Copyright © 2018 User. All rights reserved.
//
import UIKit
import CoreData
import SwiftyDropbox
var shouldLaunchCamera = false
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
enum ShortcutIdentifier: String {
case first
// MARK: - Initializers
init?(fullType: String) {
guard let last = fullType.components(separatedBy: ".").last else { return nil }
self.init(rawValue: last)
}
// MARK: - Properties
var type: String {
return Bundle.main.bundleIdentifier! + ".\(self.rawValue)"
}
}
// MARK: - Static Properties
/// Main tint color of the app
static let tintColor = UIColor(red: 122/255, green: 155/255, blue: 41/255, alpha: 1)
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DropboxClientsManager.setupWithAppKey("n81tx2g638wuffl")
DiskManager.setupOnFirstLaunch()
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
DropboxController.shared.handle(url: url)
return true
}
private func handleShortCutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
event("Shortcut pressed")
shouldLaunchCamera = true
return true
}
func applicationDidBecomeActive(_ application: UIApplication) {
Cap.uploadRemainingImages()
guard shouldLaunchCamera else { return }
shouldLaunchCamera = false
if let c = (frontmostViewController as? UINavigationController)?.topViewController as? TableView {
c.performSegue(withIdentifier: "showCamera", sender: nil)
}
}
/*
Called when the user activates your application by selecting a shortcut on the home screen, except when
application(_:,willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions) returns `false`.
You should handle the shortcut in those callbacks and return `false` if possible. In that case, this
callback is used if your application is already launched in the background.
*/
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let handledShortCutItem = handleShortCutItem(shortcutItem)
completionHandler(handledShortCutItem)
}
var frontmostViewController: UIViewController? {
var controller = window?.rootViewController
while let presentedViewController = controller?.presentedViewController {
controller = presentedViewController
}
return controller
}
}
extension AppDelegate: Logger {
static let logToken = "[AppDelegate]"
}