UserNotification


- 권한 요청


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// 노티피케이션 권한 요청
        if #available(iOS 10.0*)
        {
            let center = UNUserNotificationCenter.current()
            center.delegate = self
            
            center.requestAuthorization(options: [.badge, .alert, .sound]) {
                (granted, error) in
                if(granted)
                {
                    NSLog("===== ViewController_Main 사용자가 푸시를 허용 =====");
                }
                else
                {
                    NSLog("===== ViewController_Main 사용자가 푸시를 거부 =====");
                }
            }
            
        }
        else
        {
        }
cs



- UNUserNotificationCenterDelegate


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// MARK: - EterisNotificationUtils (UNUserNotificationCenterDelegate)
extension ViewController_Main : UNUserNotificationCenterDelegate
{
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
    {
        NSLog("===== ViewController_Main willPresent (포어그라운드 상태에서 노티 발생) =====");
        
        completionHandler([.alert, .sound, .badge])
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
        NSLog("===== ViewController_Main openSettingsFor =====");
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        NSLog("===== ViewController_Main didReceive (노티 선택) =====");
        
        self.navigationController?.popViewController(animated: true)
    }
}
cs


'Developer > Swift' 카테고리의 다른 글

Lottie (Swift)  (0) 2019.07.23
Keyboard Control  (0) 2019.07.08
UserNotification  (0) 2019.05.15
TableView - Cell Register  (0) 2019.04.25
CocoaPods 사용법  (0) 2019.04.20
Abstract Class  (0) 2019.04.20

이 글을 공유하기


댓글(0)

Designed by CMSFactory.NET