Hier einige Code, den ich vorher verwendet, ein nicht hundertprozentig, was Sie suchen, aber ich hoffe, Ihnen nützlich Sie es ändern müssen täglich
import UIKit
import UserNotifications
class ViewController: UIViewController, UNUserNotificationCenterDelegate {
var isGrantedNotificationAccess:Bool = false
@IBAction func send10SecNotification(_ sender: UIButton) {
if isGrantedNotificationAccess{
//add notification code here
//Set the content of the notification
let content = UNMutableNotificationContent()
content.title = "10 Second Notification Demo"
content.subtitle = "From MakeAppPie.com"
content.body = "Notification after 10 seconds - Your pizza is Ready!!"
//Set the trigger of the notification -- here a timer.
let trigger = UNTimeIntervalNotificationTrigger(
timeInterval: 10.0,
repeats: true)
//Set the request for the notification from the above
let request = UNNotificationRequest(
identifier: "10.second.message",
content: content,
trigger: trigger
)
//Add the notification to the currnet notification center
UNUserNotificationCenter.current().add(
request, withCompletionHandler: nil)
}
}
override func viewDidLoad() {
super.viewDidLoad()
UNUserNotificationCenter.current().requestAuthorization(
options: [.alert,.sound,.badge],
completionHandler: { (granted,error) in
self.isGrantedNotificationAccess = granted
}
)
}}
sendet werden, wenn Sie eine verwenden möchten Push-Benachrichtigung, dann müssen Sie einen Prozess auf einem Server irgendwo ausführen. Sie können planen, dass eine lokale Benachrichtigung zu einem bestimmten Zeitpunkt zugestellt wird. Der Test wird jedoch an dem Zeitpunkt festgelegt, an dem die Benachrichtigung geplant wird, nicht jedoch, wenn die Benachrichtigung zugestellt wird. – Paulw11