【问题标题】:Sending a push notification to iOS through a CLI function通过 CLI 函数向 iOS 发送推送通知
【发布时间】:2020-10-31 20:42:02
【问题描述】:

我正在尝试使用 CLI 功能向 Android 和 iOS 设备发送推送通知。当我使用 iOS 版本时,从我的函数发送时没有收到通知。但是,当我从 Firebase 控制台发送它们时,它只会在应用程序打开时收到通知。我在想我错过了设置中的一个或多个关键步骤,或者我的函数在有效负载中没有所有需要的数据。

我的函数发送如下:

return Promise.all([token]).then(result=>{

             const payload = {
                 notification: {
                     title : likename + " liked your post!",
                     "priority" : "high"
                 }
             };
              console.log(token);

             return admin.messaging().sendToDevice(token,payload);
    });

我的 iOS 应用程序设置了证书,并按如下方式实现了我的 APP 委托:

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    
    if #available(iOS 10.0, *) {
      // For iOS 10 display notification (sent via APNS)
      UNUserNotificationCenter.current().delegate = self

      let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
      UNUserNotificationCenter.current().requestAuthorization(
        options: authOptions,
        completionHandler: {_, _ in })
    } else {
      let settings: UIUserNotificationSettings =
      UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
      application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()

    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

非常感谢任何帮助,如果您需要更多信息,请告诉我。

【问题讨论】:

    标签: ios flutter push-notification google-cloud-functions apple-push-notifications


    【解决方案1】:

    经过数小时的思考,我意识到我只实现了响应 onLaunch 或 onResume 版本的代码。我必须在我的代码中实现这些方法,现在已经成功了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      相关资源
      最近更新 更多