LoginSignup
1
1

More than 5 years have passed since last update.

iOSローカル通知実装

Posted at

下記でローカル通知が可能


import UIKit
import UserNotifications
...
        let content = UNMutableNotificationContent()
        content.title = "Notification Title(BG)"
        content.subtitle = "Notification Subtitile(BG)"
        content.body = "Notification Body"
//        content.body = myLabel.text!
        content.badge = 5
        content.sound = UNNotificationSound.default

        if let path = Bundle.main.path(forResource: "DL", ofType: "jpeg") {
            content.attachments = [try! UNNotificationAttachment(identifier: "renchon", url: URL(fileURLWithPath: path), options: nil)]
        }

        let interval_time : TimeInterval = 10   //sec
        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: interval_time, repeats: false)
        let request = UNNotificationRequest(identifier: "later", content: content, trigger: trigger)
        UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1