APN 和 GCM 推送通知在科尔多瓦应用程序中打开一个 url [英] APN and GCM Push Notifications opening a url in cordova app

查看:25
本文介绍了APN 和 GCM 推送通知在科尔多瓦应用程序中打开一个 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Cordova PushPlugin 和 AngularJS,我想接收推送通知并读取有效负载中的 URL,然后在滑动打开通知时导航到该页面.

Using Cordova PushPlugin and AngularJS I want to receive a push notification and read a URL in the payload and then navigate to that page when the notification is swiped open.

这是如何实现的?

我试过了,但这是在 angular 之外的全局函数内,所以我不会怀疑 $location 起作用.虽然它不会抛出任何错误,但它也不会从有效负载导航到 url.

I tried this, but this is inside of a global function that is outside of angular so I wouldn't suspect the $location to work. It doesn't throw any errors though, but it also does not navigate to the url from the payload.

function onNotificationAPN(event) {
  $location.path(event.custom.url)
});

推荐答案

你可以试试这个:创建一个服务PushService"并像下面这样调用这个服务

You can try this: Create a service "PushService" and invoke the service like below

function onNotification(event) {
var injector = angular.element(document.body).injector();
injector.invoke(function (PushService) {
    PushService.onNotification(event);
});

}

我创建了一个工具来生成带有cordova和ionic的推送通知集成的应用程序.您可以查看 Ionic 应用程序构建器

I created a tool to generate app with push notification integration with cordova and ionic. You can check it out Ionic app builder

这篇关于APN 和 GCM 推送通知在科尔多瓦应用程序中打开一个 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆