-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathConnectionRedirectHandler.swift
41 lines (34 loc) · 1.64 KB
/
ConnectionRedirectHandler.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
//
// ConnectionRedirectHandler.swift
// IFTTT SDK
//
// Copyright © 2019 IFTTT. All rights reserved.
//
import UIKit
/// A class to handle redirections of `URL`s recieved as a part of the `Connection` activation process.
public final class ConnectionRedirectHandler {
private let redirectURL: URL
/// An `AuthenticationRedirectHandler` configured to handle a `URL`.
///
/// - Parameter redirectURL: A `URL` that is used as the redirect sent on `Connection` activation.
public init(redirectURL: URL) {
self.redirectURL = redirectURL
}
/// Handles redirects during a `Connection` activation.
///
/// Generally, this is used to handle url redirects the app recieves in `func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool` in the `AppDelgate`.
/// - Example: `AuthenticationRedirectHandler.handleApplicationRedirect(url: url, options: options)`.
///
/// - Parameters:
/// - url: The `URL` resource to open.
/// - options: A dictionary of `URL` handling options. For information about the possible keys in this dictionary, see UIApplicationOpenURLOptionsKey.
/// - Returns: True if this is an IFTTT SDK redirect. False for any other `URL`.
public func handleApplicationRedirect(url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
// Checks if the scheme matches the SDK redirect.
if url.scheme == redirectURL.scheme {
NotificationCenter.default.post(name: .connectionRedirect, object: url)
return true
}
return false
}
}