풍's토리

반응형

//

//  ViewController.swift

//  alarmTest

import UIKit

import UserNotifications

 

class ViewController: UIViewController {

 

    override func viewDidLoad() {

        super.viewDidLoad()

        

        UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge], completionHandler: {didAllow,Error in print(didAllow)

        })

        

        //in-app noti

        UNUserNotificationCenter.current().delegate = self

        // Do any additional setup after loading the view, typically from a nib.

    }

 

    @IBAction func buttonClick(_ sender: UIButton) {

        for idx in 1...5 {

            let content = UNMutableNotificationContent()

        

            content.title = "알림 테스트"

            content.subtitle = "서브 타이틀 입니다."

            content.body = "\(idx). 알림을 보냅니다."

            content.badge = idx as NSNumber

            

            let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)

            let request = UNNotificationRequest(identifier: "alertTest\(idx)", content: content, trigger: trigger)

            

            UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

        }

    }

    

}

 

//in-app noti

extension ViewController : UNUserNotificationCenterDelegate {

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping(UNNotificationPresentationOptions) -> Void) {

        completionHandler([.alert,.sound,.badge])

    }

    

    func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {

        let settingsViewController = UIViewController()

        settingsViewController.view.backgroundColor = .gray

        self.present(settingsViewController, animated: true, completion: nil)

    }

}

 

'메뉴 일곱' 카테고리의 다른 글

iOS Swift 개발 참고 링크 모음..  (0) 2019.04.22
[ios] swift 체험하기 #10 웹뷰  (0) 2019.04.16
[ios] swift 체험하기 #9 딕셔너리  (0) 2019.04.15