UNResponseManager.swift
1.7キロバイト
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
//
// UserNofiticationManager.swift
// ko-seigen
//
// Created by USER on 2017/10/04.
// Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
//
import Foundation
//
// UNNofiticationResponse.swift
// ko-seigen
//
// Created by USER on 2017/10/04.
// Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
//
import Foundation
import UserNotifications
class UNResponseManager:NSObject, UNUserNotificationCenterDelegate{
static let sharedInstance = UNResponseManager();
private var Response:[String:((_ actionIdentifier:String) -> Void )] = [:]
public func setResponse( identifier:String,response:@escaping ((_ actionIdentifier:String) -> Void ))
->UNResponseManager{
if(Response[identifier] == nil){
Response[identifier] = response
}
return self
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert,.sound])
NSLog("called")
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let id = response.notification.request.content.categoryIdentifier
if(Response[id] != nil){
Response[id]!(response.actionIdentifier)
}
completionHandler()
}
}