forked from arthurhammer/FrameGrabber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDelegate.swift
53 lines (41 loc) · 1.82 KB
/
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import InAppPurchase
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var coordinator: Coordinator?
let paymentsManager: StorePaymentsManager = .shared
let fileManager = FileManager.default
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
configureInAppPurchases()
Style.configureAppearance(for: window)
configureCoordinator()
if launchOptions?[.url] == nil {
try? fileManager.clearTemporaryDirectories()
}
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let openInPlace = options[.openInPlace] as? Bool == true
let _url = try? fileManager.importFile(at: url, asCopy: true, deletingSource: !openInPlace)
guard let url = _url,
let coordinator = coordinator else { return false }
return coordinator.open(videoUrl: url)
}
func applicationWillTerminate(_ application: UIApplication) {
try? fileManager.clearTemporaryDirectories()
paymentsManager.stopObservingPayments()
}
private func configureCoordinator() {
guard let navigationController = window?.rootViewController as? UINavigationController else {
fatalError("Wrong root view controller")
}
coordinator = Coordinator(navigationController: navigationController)
coordinator?.start()
}
private func configureInAppPurchases() {
paymentsManager.purchasedProductsStore = UserDefaults.standard
paymentsManager.startObservingPayments()
paymentsManager.flushFinishedTransactions()
}
}