【问题标题】:ionic 2 push notification not working in my custom page?ionic 2 推送通知在我的自定义页面中不起作用?
【发布时间】:2017-05-05 06:01:00
【问题描述】:

在我的 ionic 2 应用程序中,我有 2 个页面 index.html(默认加载页面)和 channel.html(应用程序/页面中不存在的一般页面)。 我在 index.html 中时会收到推送通知,但在 channel.html 中时不会收到。 谁能建议我该怎么做,以便我可以在两个页面上都收到推送通知。提前谢谢你。

【问题讨论】:

  • 你能在你收到通知的地方显示一些代码吗?
  • var push = Push.init({ android: { senderID: "XXXXXXXXX" }, ios: { alert: "true", badge: true, sound: 'false' }, windows: {} }); push.on('registration', (data) => { console.log(data.registrationId); alert(data.registrationId.toString()); }); push.on('notification', (data) => { console.log(data); alert("你好,我是推送通知"); });
  • 我在 /src/app/app.component.ts 文件中使用它。当我在 index.html 中时,我可以收到推送通知,但在单击某些按钮时切换到 channel.html 时不会。
  • 我认为你必须反其道而行之。当您收到相关页面的通知时,以数据为参数推送页面。

标签: cordova ionic2 hybrid-mobile-app


【解决方案1】:

在 ionic 2 中,创建自定义加载页面不是一个好习惯,最好将 index.html 作为默认加载页面。原因是

  • Index.html 充当所有页面的容器 src/pages.

  • 由于 index.html 充当所有页面的容器,因此任何通知都会 仅在这些页面中工作。如果您导航到存在的任何其他页面 在 src/custom_page 或某些外部 URL 中,它不被视为 离子页面,所以推送将不起作用。

  • 在离子构建期间,index.html 被构建并从 src/index.html 到 www/index.html 它不会发生在任何 自定义页面。

  • 如果您受自定义页面要求的约束,我建议您采取 你的时间和修改现有的代码,这样你就可以应付 index.html 作为默认加载页面,因为自定义加载会麻烦 您未来的项目。

【讨论】:

    猜你喜欢
    • 2017-07-11
    • 2018-12-04
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 2017-01-29
    • 2019-05-28
    • 1970-01-01
    • 2019-12-10
    相关资源
    最近更新 更多