android - @ionic-native/push 的 ionic 问题

标签 android ionic-framework

这几天我一直在尝试让推送通知在 ionic 中工作,到目前为止我已经学习了 7 个教程,但是一旦我开始测试,每个教程都会失败! 。是我一个人的问题还是所有这些教程都已经过时了?

到目前为止,我已经尝试过以下教程:

  • c-sharpcorner.com
  • saowen.com
  • medium.com
  • sitepoint.com
  • masteringionic.com
  • thielcole.github.io
  • luisjordan.net

对于这些教程中的每一个,我都遇到了有关推送模块的问题,以某种方式我不断收到这些相同的错误,不同教程之间存在一些非常小的差异,但总的来说,这些都是相同的错误,下面的内容来 self 遵循的最新教程(luisjordan 教程):

From the app.component.ts file, i get an error for the constructor:
----------------------
typescript: C:/Users/***/Documents/ionic/push-luisjordan/src/app/app.component.ts, line: 15
Cannot find name 'Push'.

L15:  constructor (platform : Platform, statusBar : StatusBar, splashScreen : SplashScreen, private push : Push) {
L16:              platform.ready().then(() => {
----------------------

And from app.module.ts file, i get an error for the providers:
----------------------
typescript: C:/Users/***/Documents/ionic/push-luisjordan/src/app/app.module.ts, line: 12
Argument of type '{ declarations: (typeof HomePage | typeof MyApp)[]; imports: (ModuleWithProviders | typeof
Browse...' is not assignable to parameter of type 'NgModule'. Types of property 'providers' are
incompatible. Type '(typeof SplashScreen | PushOriginal | { provide: typeof ErrorHandler; useClass: typeof
IonicError...' is not assignable to type 'Provider[]'. Type 'typeof SplashScreen | PushOriginal | { provide:
typeof ErrorHandler; useClass: typeof IonicErrorH...' is not assignable to type 'Provider'. Type
'PushOriginal' is not assignable to type 'Provider'. Type 'PushOriginal' is not assignable to type
'ClassProvider'. Property 'provide' is missing in type 'PushOriginal'.

L12:  @NgModule({                                                                                                                                                                                                                                                                                                        
L13:    declarations: [

为了防止把这个东西变成更大的文本墙,我制作了下面的pastebin页面,它包含上面发布的相同错误,但更重要的是它还包含app.component.ts和app.module的代码.ts

https://pastebin.com/RUH9egA9

为了帮助加快速度,这里是版本号的概述以及我在其他 ionic 问题上看到的常见问题的一些回复:

$ ionic info

Ionic:

   ionic (Ionic CLI)  : 4.8.0 (C:\Users\Olivier\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.1

Cordova:

   cordova (Cordova CLI) : 8.1.2 (<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="66050914020910074b0a0f04265e48574857" rel="noreferrer noopener nofollow">[email protected]</a>)
   Cordova Platforms     : android 7.1.4
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.3.2, (and 7 other plugins)

System:

   NodeJS : v10.2.1 (C:\Program Files\nodejs\node.exe)
   npm    : 6.5.0
   OS     : Windows 10



$ ionic cordova plugins
> cordova plugin ls

You have been opted out of telemetry. To change this, run: cordova telemetry on.
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 2.3.2 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-support-google-services 1.1.0 "cordova-support-google-services"
phonegap-plugin-multidex 1.0.0 "Multidex"
phonegap-plugin-push 2.2.3 "PushPlugin"



$ ionic cordova platform list
> cordova platform ls

You have been opted out of telemetry. To change this, run: cordova telemetry on.
Installed platforms:
  android 7.1.4
Available platforms:
  browser ~5.0.1
  ios ~4.5.4
  osx ~4.0.1
  windows ~6.0.0
  • 在工作目录中,我使用“npm install --save @ionic-native/push”安装了模块
  • 我已确保添加 Android 平台,并使用“ionic cordova emulate android”进行测试
  • 我已经编辑了 config.xml,使其具有与我的 firebase 应用程序匹配的小部件 ID(不过我猜这有点超前了?)

有人知道可能出了什么问题吗?我已经读了好几天了,但我仍然不知道我可能会错过什么?每次我遇到相同的问题时, ionic 不会接受推送模块......:(

提前致谢,如果有人在本墙文本后还有任何其他问题,请随时询问。

最佳答案

看起来 Ionic 团队最近对其原生插件进行了更改。

您似乎已经安装了 ionic 4 支持的插件(版本 >= 5.0.0)。 由于您使用的是 ionic 3,请卸载该插件并安装 4.20.0 版本。

npm uninstall @ionic-native/push

然后

npm i -s @ionic-native/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="acdcd9dfc4ec98829e9c829c" rel="noreferrer noopener nofollow">[email protected]</a>

更详细的解释可以查看这个答案https://stackoverflow.com/a/54398403/6617276

关于android - @ionic-native/push 的 ionic 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54402772/

相关文章:

Android 错误 - 访问被拒绝无法保存裁剪的图像

css - Cordova css 属性在所有设备上的工作方式不同

css - 如何在 Ionic 4 中更改选项卡栏和选项卡图标的背景颜色

Android - 节奏调整?

android - 如何在 Activity 中显示后退按钮

android - ViewPager,与多个选项卡的 RecyclerView 相同的 fragment

css - 键盘将模态弹出窗口中的文本字段推到顶部

javascript - ionic 如何转换和重新加载页面

java - 如何使用java获取utf-8字符集中的页面源

android - 在android中使用DB登录注册