【问题标题】:Ionic 5 push notifications with Capacitor带电容器的 Ionic 5 推送通知
【发布时间】:2020-03-24 01:24:41
【问题描述】:

我的 Ionic 5 应用想要发送推送通知。我能找到的唯一指南是Using Push Notifications with Firebase in an Ionic + Angular App

为什么需要 Firebase?我可以在没有 Firebase 的情况下发送推送通知吗?

我还是尝试了这个设置。我没有走很远。

指南有这个代码:

    // Request permission to use push notifications
    // iOS will prompt user and return if they granted permission or not
    // Android will just grant without prompting
    PushNotifications.requestPermission().then( result => {
      if (result.granted) {
        // Register with Apple / Google to receive push via APNS/FCM
        PushNotifications.register();
      } else {
        // Show some error
      }
    });

但是,Typescript 抱怨正确的方法是 requestPermissions() 而不是 requestPermission()

在 XCode 中运行时两者都失败,可能是因为我没有设置 pod。

Ionic 5 + Capacitor 有哪些选项可以在不使用 Firebase 的情况下发送推送通知?

【问题讨论】:

    标签: ionic-framework push-notification apple-push-notifications capacitor


    【解决方案1】:

    编辑:

    该指南现已更新为 Capacitor 3。

    电容器2指南可以找到here

    旧: 指南已更新至电容器 2,但电容器 2 仍处于测试阶段。

    使用下一个标签安装它

    npm install @capacitor/cli@next
    npm install @capacitor/core@next
    npm install @capacitor/ios@next
    npm install @capacitor/android@next
    

    Capacitor 默认使用 APNS,因此如果您不在 AppDelegate.swift 中进行更改,它应该可以正常工作。

    【讨论】:

    • 为什么需要 Firebase?我可以不通过 Firebase 直接通过 Apple/Android 通知中心发送通知吗?
    • 这是一个 firebase 指南,因为人们想知道如何在 iOS 上使用 firebase,并且有人编写了该指南,但正如我所说,iOS 默认使用 APNS(Apple Push Notification Service)。 Android 使用 firebase 是因为 google 说你必须使用它,他们在一年前杀死了 GCM,不确定“android 通知中心”是什么
    • 无论你使用APNS还是firebase,电容器代码都是一样的,但是指南解释了如何添加依赖以及如何获取firebase令牌,只要你不进行原生更改相同的 JavaScript 代码将起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    相关资源
    最近更新 更多