본문 바로가기
🍎 iOS/UI

[iOS]푸쉬알림 보내기

by Fomagran 💻 2020. 1. 23.
728x90
반응형

import UserNotifications

 

  override func viewDidLoad() {
        super.viewDidLoad()
        
        let center = UNUserNotificationCenter.current()
        center.requestAuthorization(options: [.alert,.sound]) { (granted, error) in
            
        }
        let content = UNMutableNotificationContent()
        content.title = "될까요?"
        content.body = "되겠지"
        
        let date = Date().addingTimeInterval(3)
        let dateComponents = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: date)
       let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
        
        let uuidString = UUID().uuidString
        let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger)
        center.add(request) { (error) in
            
        }
    }

728x90
반응형

댓글