0

我已經知道了這個代碼,可以iOS的10之前使用:什麼是UserNotification框架等同於didReceive通知:UILocalNotification?

func application(_ application: UIApplication, didReceive notification: UILocalNotification) { 

} 

然而,它的大幅貶值,我只是想問問有沒有這相當於UserNotifications框架的任何方法或我只是要得到通過這個警告?

請注意,我希望應用程序在應用程序處於後臺或終止狀態時執行某些操作。

+0

看到這個https://alessiopapazzoni.com/2016/09/29/ios-10-uilocalnotification-is-dead/ –

回答

1

當應用程序在前臺收到通知時,不推薦使用的方法是通知委託。現在UNUserNotificationCenterDelegate做同樣的事情:

func userNotificationCenter(
    UNUserNotificationCenter, 
    willPresent: UNNotification, 
    withCompletionHandler: @escaping (UNNotificationPresentationOptions) -> Void 
) 

當通知被傳遞到前臺應用程序調用。

Documentation.

+0

約當應用程序被終止或在後臺是什麼? –

+0

@天仙,沒事。您無法通過通知提升您的應用。但是您可以處理通知操作,在這種情況下,應用程序將在後臺運行。另外,我直接回答你的問題,請接受它。 – kelin