-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAppDelegate.swift
68 lines (53 loc) · 2.11 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// AppDelegate.swift
// SoF-MedList
//
// Created by Pascal Pfiffner on 6/20/14.
// Copyright (c) 2014 SMART Platforms. All rights reserved.
//
import UIKit
import SMART
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var endpointProvider = EndpointProvider()
func application(_ app: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
let splitViewController = self.window!.rootViewController as! UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.endIndex-1] as! UINavigationController
splitViewController.delegate = navigationController.topViewController as! DetailViewController
// SMART tint color
window?.tintColor = UIColor(red:0.41, green:0.14, blue:0.44, alpha:1.0)
// configured endpoints
endpointProvider.endpoints = configuredEndpoints()
let masterNavi = splitViewController.viewControllers[splitViewController.viewControllers.startIndex] as! UINavigationController
let master = masterNavi.topViewController as! MasterViewController
master.endpointProvider = endpointProvider
return true
}
// You need this for Safari and Safari Web View Controller to work
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
guard let smart = endpointProvider.activeEndpoint?.client else {
window?.rootViewController?.show(error: AppError.noActiveEndpoint, title: "Not Set Up")
return false
}
if smart.awaitingAuthCallback {
return smart.didRedirect(to: url)
}
return false
}
}
enum AppError: Error, CustomStringConvertible {
case noEndpointProvider
case noActiveEndpoint
case noPatientSelected
var description: String {
switch self {
case .noEndpointProvider:
return "No endpoint provider is present, cannot continue"
case .noActiveEndpoint:
return "No endpoint (server) has been selected yet, please do that first"
case .noPatientSelected:
return "No patient has been selected, please do that first"
}
}
}