-
Notifications
You must be signed in to change notification settings - Fork 2
/
EMActionButtonExtension.swift
37 lines (30 loc) · 1.11 KB
/
EMActionButtonExtension.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
//
// EMActionButtonExtension.swift
// Euromsg
//
// Created by Orhun Akmil on 9.08.2022.
//
extension Euromsg {
@available(iOS 10.0, *)
static func handleActionButton(_ data: Data?, _ response: UNNotificationResponse?) {
guard let json = data, let response = response else {
print(">>> no json exist")
return
}
guard let message = try? JSONDecoder.init().decode(EMMessage.self, from: json) else {
print(">>>json parse error")
return
}
guard let buttons = message.buttons else {
print(">>> no buttons exist")
return
}
for button in buttons where button.identifier == response.actionIdentifier {
print(">>> response.actionIdentifier ==> \(response.actionIdentifier)")
print(">>> button.identifier ==> \(button.identifier ?? "")")
print(">>> button.link ==> \(button.url ?? "")")
guard let link = URL(string: button.url ?? "") else { return }
UIApplication.shared.openURL(link)
}
}
}