【问题标题】:Handle push notification when app is in Background or Running state not when app is terminated当应用程序处于后台或运行状态而不是应用程序终止时处理推送通知
【发布时间】:2019-03-30 17:03:29
【问题描述】:

我在一个项目中工作,其中客户要求就像显示推送通知直到应用程序未终止。通过将 FCM 令牌发送到后端,使用 Firebase 集成完成推送通知。我还有一个 API 用于在应用程序终止时删除 FCM 令牌,但在应用程序终止之前无法执行大约 30 秒。无论如何,当推送通知到达时,是否从应用程序端检查仅在应用程序正在运行或后台状态时显示。

【问题讨论】:

  • 改为点击API for Deleting FCM token when app is in background
  • @AmirKhan 那么当应用程序是后台时我会收到推送通知吗?因为我已经从 API 中删除了 FCM 令牌
  • 否,只有当应用处于前台时,应用才会收到通知。
  • 哦,对不起,我的错。我弄错了。您可以实现套接字连接,服务器将检查用户是否仍然连接。
  • 如果app当前运行在background and not suspended,系统调用applicationWillTerminate: of its app delegate prior to termination. Other than applicationWillTerminate`不会被调用。在这里查看 - stackoverflow.com/questions/29416375/…

标签: ios swift iphone


【解决方案1】:

接收最低 iOS 10 版本的显示通知。

     // Function call when App is in foreground State

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

    }

   // Function call when App in Background State 

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


   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    • 2016-05-05
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多