UNUserNotificationCenterを使って、通知と同時に関数を実行するということはできますか?
もしできるのであれば、何という関数を使えばできるのか教えていただきたいです。
一定時間ごとに通知を行い、一回ごとに通知の内容を更新したいので、通知と同時に値を更新する関数を実行したいのです。
しかし、Apple公式のものだと、
swift
1let content = UNMutableNotificationContent() 2content.title = NSString.localizedUserNotificationString(forKey: 3 "Hello!", arguments: nil) 4content.body = NSString.localizedUserNotificationString(forKey: 5 "Hello_message_body", arguments: nil) 6 7// Deliver the notification in five seconds. 8content.sound = UNNotificationSound.default() 9let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, 10 repeats: false) 11 12// Schedule the notification. 13let request = UNNotificationRequest(identifier: "FiveSecond", content: content, trigger: trigger) 14let center = UNUserNotificationCenter.current() 15center.add(request, withCompletionHandler: nil)
のように、関数を設定する場所がなく、
通知のみしか実行できないようです。
UNNotificationRequestや UNUserNotificationCenter.current().add()を調べてみましたが、関数を設定するオプションは見当たりませんでした。
リモート通知の場合、addObserver()で関数を指定することができるようなのですが、これしか方法はないのでしょうか?
追記:
とりあえず、ローカル通知を1分ごとに内容を変えて通知する場合なら、1分一個のローカル通知を大量に登録しておくことで実現できるかもしれないので、まずはこれを試してみます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。