【问题标题】:I Need to call an API after receiving notification (app is in open, background, in active) using Firebase我需要在使用 Firebase 收到通知(应用程序处于打开、后台、活动状态)后调用 API
【发布时间】:2019-04-10 07:25:07
【问题描述】:

收到通知后需要调用 API(应用处于打开、后台、非活动状态)

如果应用程序处于打开状态,则可以正常工作 但是如果应用程序在后台,不活动它就不能工作

在前台显示通知时会调用以下方法

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

一旦我们点击收到的通知,以下方法将调用

func userNotificationCenter(_ center: UNUserNotificationCenter, 
                            didReceive response: UNNotificationResponse, 
                            withCompletionHandler completionHandler: @escaping () -> Void) {}

那么,当应用处于后台、非活动状态时,一旦我收到通知,我该如何调用 API

【问题讨论】:

  • 如果应用程序“未运行”,我认为您无法运行任何代码,因为您无法在应用程序内部获得任何控制权。
  • 试试这个解决方案,它可能是你正在寻找的东西stackoverflow.com/a/50044201/5084797

标签: ios swift push-notification apple-push-notifications firebase-cloud-messaging


【解决方案1】:
  • 当应用程序处于后台模式时,该方法不会被调用,然后用户需要点击通知才会被调用。
  • 您需要集成 Apple pushkit,它将向设备发送静默通知,并且在其委托方法中您可以调用 API

    https://developer.apple.com/documentation/pushkit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多