/
EventUtils.swift
91 lines (70 loc) · 2.96 KB
/
EventUtils.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Copyright Airship and Contributors */
import Foundation
class EventUtils {
private static let push: () -> PushProtocol = { Airship.push }
class func isValid(latitude: Double) -> Bool {
guard latitude >= -90 && latitude <= 90 else {
AirshipLogger.error("Invalid latitude \(latitude). Must be between -90 and 90")
return false
}
return true
}
class func isValid(longitude: Double) -> Bool {
guard longitude >= -180 && longitude <= 180 else {
AirshipLogger.error("Invalid longitude \(longitude). Must be between -180 and 180")
return false
}
return true
}
class func notificationTypes() -> [AnyHashable]? {
var notificationTypes: [AnyHashable] = []
let authorizedSettings = push().authorizedNotificationSettings
if (UAAuthorizedNotificationSettings.badge.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("badge")
}
#if !os(tvOS)
if (UAAuthorizedNotificationSettings.sound.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("sound")
}
if (UAAuthorizedNotificationSettings.alert.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("alert")
}
if (UAAuthorizedNotificationSettings.carPlay.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("car_play")
}
if (UAAuthorizedNotificationSettings.lockScreen.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("lock_screen")
}
if (UAAuthorizedNotificationSettings.notificationCenter.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("notification_center")
}
if (UAAuthorizedNotificationSettings.criticalAlert.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("critical_alert")
}
if (UAAuthorizedNotificationSettings.scheduledDelivery.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("scheduled_delivery")
}
if (UAAuthorizedNotificationSettings.timeSensitive.rawValue & authorizedSettings.rawValue) > 0 {
notificationTypes.append("time_sensitive")
}
#endif
return notificationTypes
}
class func notificationAuthorization() -> String? {
let authorizationStatus = push().authorizationStatus
switch authorizationStatus {
case .notDetermined:
return "not_determined"
case .denied:
return "denied"
case .authorized:
return "authorized"
case .provisional:
return "provisional"
case .ephemeral:
return "ephemeral"
default:
return "not_determined"
}
}
}