2017-12-13 9 views
-1

スウィフト4でローカル通知がトリガーされたことをどのように知ることができますか教えてください。私はそれが動作していないように見えたすべてを試みました。iosローカル通知がいつトリガされるかを知るには?

+0

このリンクを確認してくださいhttps://peterwitham.com/swift-archives/ios-10-local-notifications-using-swift-3/ –

+0

あなたは_everything_をどういう意味ですか?あなたはそれを詳しく説明できますか? – holex

答えて

0

あなたは通知がバックグラウンドで起動し、ユーザーが通知をタップさ

let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 5, repeats: true) 
    let content = UNMutableNotificationContent.init() 
    content.title = "Danger Will Robinson" 
    content.subtitle = "Something This Way Comes" 
    content.body = "I need to tell you something, but first read this." 

    let notification = UNUserNotificationCenter.current() 
    notification.add(UNNotificationRequest.init(identifier: "notification", content: content, trigger: trigger), withCompletionHandler: nil) 

としてローカル通知を作成することができます。通知がトリガされ、アプリがフォアグラウンドになっている

public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Swift.Void) 

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

あなたはトリガを取得するためにUNUserNotificationCenterDelegateを確認しなければなりません。

あなたがappDelegateでローカル通知を初期化することをお勧めします。

関連する問題