Ahm*_*med 4 ios localnotification swift
以前我使用以下代码来区分应用程序启动时我的通知是本地还是远程
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if (launchOptions?[UIApplication.LaunchOptionsKey.localNotification] != nil)
{
}
if (launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] != nil)
{
}
}
Run Code Online (Sandbox Code Playgroud)
条件是我的应用程序被杀死,我正在从通知中打开它。
问题是这个方法
if (launchOptions?[UIApplication.LaunchOptionsKey.localNotification] != nil)
{
}
Run Code Online (Sandbox Code Playgroud)
已弃用,从通知中心打开应用程序时不会调用以下方法
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {}
Run Code Online (Sandbox Code Playgroud)
Ank*_*wal 10
您也可以检查通知类型userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:,
类层次结构是:
UNNotificationResponse>UNNotification>UNNotificationRequest>UNNotificationTrigger
有 4 种类型的触发器UNNotificationRequest:
UNLocationNotificationTriggerUNPushNotificationTriggerUNTimeIntervalNotificationTriggerUNCalendarNotificationTrigger就用,
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.notification.request.trigger is UNPushNotificationTrigger {
print("remote notification");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1612 次 |
| 最近记录: |