具有 Firebase 消息传递和 Firebase 动态链接的 Cordova Ionic 项目

Cordova Ionic project with Firebase Messaging and Firebase Dynamic Links

在我们正在构建的应用程序中,我们需要 Firebase Dynamic Link,因为注册是使用 Firebase 电子邮件 link 登录。此登录将向提供的电子邮件地址发送一封电子邮件,单击该电子邮件地址后,将打开带有动态 link 的应用程序。为了让我们的用户保持参与,我们还喜欢发送推送通知。当我在 GitHub 上使用 chemerisuk 的版本时,我可以让他们在 Android 上一起工作。我什至得到了一个 iOS 构建,但我一直无法在 iOS 上获得令牌。收到此错误消息:

Failed to fetch default token Error Domain=com.firebase.iid Code=1003 "(null)"

我仔细检查了我的 Firebase 项目设置(捆绑 ID、应用程序 ID 前缀、云消息发送者 ID、云消息 apn 密钥)和我的 Apple 设置(证书、配置文件、密钥和标识符)。我已经在模拟器和真实设备上试过了。我尝试过开发版本、App Store 存档和临时存档。

遗憾的是,Dynamic Links 未包含在 Cordova Firebase 插件中。当我尝试添加不同的 fcm 插件时,它包含完整的 Firebase Core,这与 Dynamic Links.

冲突

我觉得我真的很接近,谁有使用这种插件组合的经验并让它在iOS上工作?

这是我的环境:

Ionic:

  ionic (Ionic CLI)  : 4.0.2 (/usr/local/lib/node_modules/ionic)
  Ionic Framework    : ionic-angular 3.9.2
  @ionic/app-scripts : 3.1.8

Cordova:

  cordova (Cordova CLI) : 8.0.0
  Cordova Platforms     : android 7.0.0, ios 4.5.5

System:

  Android SDK Tools : 26.1.1
  ios-deploy        : 1.9.2
  ios-sim           : 6.1.2
  NodeJS            : v8.11.3 (/usr/local/bin/node)
  npm               : 5.6.0
  OS                : macOS High Sierra
  Xcode             : Xcode 9.4.1 Build version 9F2000

Environment:

  ANDROID_HOME : /Users/user/Library/Android/sdk/

我的(相关)Cordova config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget android-packageName="com.example.android" android-versionCode="10001" id="com.example.app" ios-CFBundleIdentifier="com.example.ios" ios-CFBundleVersion="1.0.1" version="1.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Example</name>
    <description>Some description</description>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="ScrollEnabled" value="false" />
    <preference name="BackgroundColor" value="0xff168aa5" />
    <preference name="android-minSdkVersion" value="16" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="Orientation" value="portrait" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <platform name="android">
        <resource-file src="google-services.json" target="app/google-services.json" />
        <allow-intent href="market:*" />
        <icon />
        <splash />
    </platform>
    <platform name="ios">
        <resource-file src="GoogleService-Info.plist" />
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <icon />
        <splash />
    </platform>
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
    <plugin name="cordova-plugin-device" spec="^2.0.2" />
    <plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
    <plugin name="cordova-plugin-ionic-webview" spec="^1.2.1" />
    <plugin name="cordova-plugin-ionic-keyboard" spec="^2.1.2" />
    <plugin name="cordova-plugin-x-socialsharing" spec="^5.4.1" />
    <plugin name="cordova-plugin-qrscanner" spec="^2.6.0" />
    <allow-navigation href="http://192.168.178.19:8101" />
    <plugin name="cordova-plugin-firebase-dynamiclinks" spec="^1.0.0">
        <variable name="APP_DOMAIN" value="example.com" />
        <variable name="PAGE_LINK_DOMAIN" value="ab123.app.goo.gl" />
        <variable name="FIREBASE_DYNAMIC_LINKS_VERSION" value="+" />
    </plugin>
    <plugin name="cordova-plugin-firebase-messaging" spec="^1.1.0">
        <variable name="FIREBASE_MESSAGING_VERSION" value="17.1.+" />
        <variable name="ANDROID_SUPPORT_VERSION" value="27.+" />
    </plugin>
    <engine name="android" spec="7.0.0" />
    <engine name="ios" spec="4.5.5" />
</widget>

因为我只使用了 Firebase 库的一部分,所以我没有包括 Firebase Analytics,因为我没有使用它。显然,它是其余插件运行所必需的。所以安装 cordova-plugin-firebase-analytics 是我的解决方法。

对于某些人来说,这是为了确保他们拥有正确的 Firebase 项目设置。转到 Firebase > 云消息传递 > iOS 应用程序配置并确保您已上传有效的 APNs 身份验证密钥或 APNs 证书。

希望这对想要同时使用 Firebase 消息传递和 Firebase 动态链接的其他人有所帮助!