UserNofitication.swift
1.82キロバイト
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
import Foundation
//
// UNNofitication.swift
// ko-seigen
//
// Created by USER on 2017/10/04.
// Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
//
import Foundation
import UserNotifications
class UserNofitication:NSObject{
static let sharedInstance = UserNofitication()
@available(iOS 10.0, *)
public func easyNofitication(
identifier : String,
title : String,
body : String,
actions : [UNNotificationAction],
completionHandler :((Error?) -> Void)?,
response :UNResponseManager
){
let category = UNNotificationCategory(identifier: identifier,
actions: actions ,
intentIdentifiers: [],
options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
let content = UNMutableNotificationContent()
content.title = title
content.body = body
content.sound = UNNotificationSound.default()
content.categoryIdentifier = identifier
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: identifier,
content: content,
trigger: trigger)
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge, .sound]) { (val,err) in
}
center.delegate = UNResponseManager.sharedInstance
center.add(request, withCompletionHandler:completionHandler)
}
}