当我收到远程通知时,为什么我的本地通知没有被发送?

时间:2016-10-24 15:45:49

标签: swift push-notification swift3 firebase-cloud-messaging localnotification

我正在尝试在收到远程FCM通知时发送位置通知,因为据我所知FCM通知不支持操作按钮。但本地通知有时只发送,在我看来它是随机的。我总是得到远程通知。我希望在所有三个州,前台,背景或应用程序被杀时获取本地通知。

在这里我在didFinishLoadingWithOptions中添加按钮:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    if UIApplication.shared.applicationState == UIApplicationState.active {
        // Do something you want when the app is active
    } else {
        // Do something else when your app is in the background
    }

    // fire a local notification upon receiving FCM notification
    let localNotification = UILocalNotification() 
    localNotification.alertTitle = "Notification Title"
    localNotification.alertBody = "more details"
    localNotification.alertAction = "ShowDetails"
    localNotification.fireDate = NSDate().addingTimeInterval(5) as Date
    localNotification.soundName = UILocalNotificationDefaultSoundName
    localNotification.applicationIconBadgeNumber = 1
    localNotification.category = "BOOKING_CATEGORY"
    UIApplication.shared.scheduleLocalNotification(localNotification)

    print("Push notification received bkg: \(userInfo)")
    print("completed"  , completionHandler)
}

我在这里创建本地通知:

{{1}}

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

为了确保您的应用始终处理通知的显示方式(即使其未运行或位于后台),您还需要设置The server mysql version: 5.5.52-cll Local version mysql: 5.6.17 - MySQL Community Server (GPL) Localhost returned the proper results, with NO MISTAKE, while the server mysql still returns wrong results.. 有效负载 ,例如< / p>

GROUP BY TNew.oid_id, TNew.aid

设置data有效负载会触发FCM代表客户端应用自动向最终用户设备显示消息。如果您使用数据有效负载,则可以完全控制如何显示通知。

有关详细信息,请查看https://firebase.google.com/docs/cloud-messaging/concept-options