-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
42 lines (30 loc) · 1.26 KB
/
AppDelegate.swift
File metadata and controls
42 lines (30 loc) · 1.26 KB
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
//
// AppDelegate.swift
// GTMAppAuth-Swift
//
// Created by Grant K2 on 20/02/2018.
// Copyright © 2018 Google. All rights reserved.
//
import Cocoa
import GTMAppAuth
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow?
var currentAuthorizationFlow:OIDAuthorizationFlowSession?
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Register for Call back URL events
let aem = NSAppleEventManager.shared();
aem.setEventHandler(self, andSelector: #selector(AppDelegate.handleGetURLEvent(event:replyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func applicationWillFinishLaunching(notification: NSNotification?) {
// -- launch the app with url
}
@objc func handleGetURLEvent(event: NSAppleEventDescriptor, replyEvent: NSAppleEventDescriptor) {
let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue!
let url = URL(string: urlString!)!
currentAuthorizationFlow?.resumeAuthorizationFlow(with: url)
}
}