我有一个 Cordova 应用程序(codova(3.4.0)在 iOS 上运行,很快也会在 Android 上运行。推送通知已实现并正常工作。我无法通过推送通知检测应用程序何时启动并将应用程序重定向到右侧页。
注意:这与应用在后台运行时从推送通知启动应用无关。仅当应用程序完全关闭时!
我现在有以下工作流程:
正常启动:
从推送通知冷启动应用程序:
如您所见,冷应用启动场景转到启动视图,这是不必要的,导致用户等待第一个视图加载,然后再次重定向。
问题是当 deviceready 触发时,我的 javascript 代码还不知道即将到来的推送通知,所以我正在寻找解决这个问题的方法。
有没有办法将额外的参数传递给 deviceready cordova 事件?或者有人有其他想法或解决方案来解决这个问题吗?
javascript push-notification ios cordova phonegap-pushplugin
尝试使用PushPlugin处理推送通知.以下是我的代码.
onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
//alert('registration id = '+e.regid);
sDeviceId = e.regid;
//alert(sDeviceId);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = '+e.message);
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
if ( e.foreground )
{
alert("Notification Received");
}
else
{ // otherwise we were launched because the user …Run Code Online (Sandbox Code Playgroud) push-notification phonegap-plugins cordova phonegap-pushplugin
我正在使用 IONICFramework,我想在收到推送通知后设置我的应用程序的徽章。
当我的应用程序关闭时,有没有办法做到这一点?
我的问题与stackoverflow的"doze-mode-and-gcm-notifications"和"android-doze-mode-gcm-priority"问题有关,但由于两者的解决方案都是使用Google Play Service 8.3.0,因此无法解决我的情况.
我通过GCM向我的应用程序发送静默(不直接显示给用户)推送通知具有高优先级.其中一些通知然后触发各种http请求以发送或从我的Web服务获取信息/文件.由于我们需要能够随时执行这些操作,因此我们必须处理手机进入打盹模式的情况.
GCM通知正确唤醒应用程序,但三星S6上的http请求失败(它们总是返回超时错误).cordova-plugin-network-information不提供插件脱机的信息.
在Nexus 5设备上进行的相同测试完全正常.
具有正常优先级的GCM通知由我的Samsung S6设备处理,处于IDLE状态.(根据android doze文档,在IDLE状态下,设备不会收到任何具有正常优先级的GCM通知,当设备切换到IDLE_MAINTENANCE状态时会处理这些通知.)
Nexus 5
两者都启用了开发人员选项和usb调试
我使用这些命令来激活打盹:
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle force-idle
Run Code Online (Sandbox Code Playgroud)
检查当前状态的命令:
adb shell dumpsys deviceidle | grep mState
Run Code Online (Sandbox Code Playgroud)
切换状态的命令:
adb shell dumpsys deviceidle step
Run Code Online (Sandbox Code Playgroud)
从那里我只使用Postman使用以下数据请求gcm API:
POST https://android.googleapis.com/gcm/send
Run Code Online (Sandbox Code Playgroud)
标题:
Authorization : key=<MYAPIKEY>
Content-Type : application/json
Run Code Online (Sandbox Code Playgroud)
身体(RAW):
{
"data": {
"key": {"key":"value"},
"content-available": …Run Code Online (Sandbox Code Playgroud) android samsung-mobile cordova google-cloud-messaging phonegap-pushplugin
我已经设置了推送通知插件并调用了register方法,但它只返回一个字符串"OK"而不是设备ID.我如何获得注册的设备ID?
$window.plugins.pushNotification.register(
function (result) {
q.resolve(result); //this always just returns the string "OK", how do I get the device ID?
},
function (error) {
console.log(error);
q.reject(error);
},
config);
return q.promise;
},
Run Code Online (Sandbox Code Playgroud)
e.regid为null,取自此示例
// Android and Amazon Fire OS
function onNotification(e) {
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
// Your GCM push server needs to know the regID before it …Run Code Online (Sandbox Code Playgroud) 我正试图在Ionic应用程序中为我的推送通知实现自定义声音.我将声音文件复制到www /也设置了插件选项,如下所示
//In app.run
$ionicPush.init({
"debug": true,
"onNotification": function(notification){
$cordovaDialogs.alert(notification.message, 'Notification', 'OK').then(function(){
console.log(notification);
});
}
"onRegister": function(data) {
console.info("New device registered with token "+data.token);
}
"pluginConfig": {
"ios": {
"badge": true,
"sound": true
},
"android": {
"iconColor": "#343434"
}
}
});
//In my main controller -
$scope.saveUserDeviceReg = function(data){
var ionicUser = Ionic.User.current();
if(!ionicUser.id){
ionicUser.id = $scope.user.userId;
}
ionicUser.set('name', $scope.user.name);
ionicUser.set('image', $scope.user.profilePic);
ionicUser.set('email', $scope.user.email);
$ionicPush.addTokenToUser(ionicUser);
ionicUser.save();
if($scope.user.devices){
$scope.user.devices[data.token] = true;
$scope.user.$save().then(function(success){
console.log("User device saved");
},function(error){
console.error("Error saving user device");
}); …Run Code Online (Sandbox Code Playgroud) 我将FIREBASE CLOUD MESSAGING服务与我的离子产品和phonegap-plugin-push cordova插件一起使用,以从PHP BACK END获取推送通知。
当我尝试获取推送通知时,php end将获得如下所示的成功结果。
样本推送数据有效载荷
{“ multicast_id”:8853634389214913500,“ success”:1,“ failure”:0,“ canonical_ids”:0,“ results”:[{“ message_id”:“ 0:1495614850271706%39688dd8f9fd7ecd”}]}
技术规格:
cordova推送通知插件版本:1.9.4
平台和版本:Ionic V1
Ionic CLI版本:2.1.13
科尔多瓦版本:科尔多瓦--6.4.0
适用于cordova的Android平台:6.0.0
Android)我测试过的设备供应商:三星,华为,小米等。
示例代码说明了以下问题
离子部分:
//推送通知if(window.cordova){if(!localStorage.getItem('device_token')){var apkId = 0; var iosId = 0; var options = {android:{senderID:MY FCM SENDER ID,icon:“ alert”,},ios:{alert:“ true”,徽章:“ true”,声音:“ true”},Windows:{}};
//localStorage.getItem('gcmRegId')
// initialize
$cordovaPushV5.initialize(options).then(function () {
// start listening for new notifications
$cordovaPushV5.onNotification();
// start listening for errors
$cordovaPushV5.onError();
// register to get registrationId
$cordovaPushV5.register().then(function (data) {
//alert("GCM"+data);
// if Android device. …Run Code Online (Sandbox Code Playgroud)php cordova ionic-framework phonegap-pushplugin firebase-cloud-messaging
目前,我正在开发一个应用程序。对于通知,我一直在使用phonegap-plugin-push与Firebase结合使用。
我正在为Android和iOS使用此插件。在Android上,它工作正常,请确保我一直遇到问题,但现在已全部完成。另一方面,IOS无法正常工作。该应用程序甚至无法构建。
如果我构建,则会出现此错误:
**建立失败**
以下构建命令失败:
CopyPlistFile /Users/gio/app/Project/platforms/ios/build/emulator/Project.app/GoogleService-Info.plist / Users / gio / App / App / Project / platforms / ios / Project / Resources / GoogleService-Info。 plist(1个失败)
错误:命令的错误代码65:带有args的xcodebuild:-xcconfig,/ Users / gio / app / Project / platforms / ios / cordova / build-debug.xcconfig,-workspace,Project.xcworkspace,-scheme,Project,-configuration ,调试,-sdk,iphonesimulator,-destination,platform = iOS Simulator,名称= iPhone SE,build,CONFIGURATION_BUILD_DIR = / Users / gio / app / Project / platforms / ios / build / emulator,SHARED_PRECOMPS_DIR = / Users / gio / app /项目/平台/ ios …
我在iOS上使用Cordova 3.5.0.
我的应用程序加载,'deviceReady'事件被触发,但直到我将我的应用程序放在后台(通过转到主屏幕)才执行插件操作.
当我回到我的应用程序时,'resume'处理程序被触发,日志显示在LLDB中,PushNotification插件开始侦听事件并尝试注册推送通知.
为什么只有在我的应用程序进入睡眠状态后才会发生这种情况?
这些是已安装的插件(cordova plugins ls):
com.patrickheneise.cordova.statusbar 0.0.2 "Status Bar"
com.phonegap.plugins.PushPlugin 2.2.1 "PushPlugin"
com.phonegap.plugins.actionsheet 1.0.0 "ActionSheet"
org.apache.cordova.console 0.2.10-dev "Console"
org.apache.cordova.dialogs 0.2.9-dev "Notification"
org.apache.cordova.vibration 0.3.10-dev "Vibration"
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我正在尝试按照文档中的描述添加phonegap-push-plugin .
我发现这个线程列出了问题,但没有给出解决方案.
正如文档中的解释,我在[我的项目文件夹]中做了一个CLI: ionic plugin add phonegap-plugin-push --variable SENDER_ID="[project id from Google Developper Console]"
在第一天,我遇到了Cordova和Cordova-android版本的问题.我将Cordova从6.3.0更新到6.4.0,然后执行了CLI:ionic platform rm android删除现有版本的5.2 Cordova-android项目.
在那之后当我做的时候,ionic info我得到:
如果我做了,ionic platform ls我得到:可用的平台:
现在我启动时唯一的问题ionic plugin add phonegap-plugin-push --variable SENDER_ID="[project id from Google Developper Console]" 是这条消息:
错误:找不到插件"phonegap-plugin-push"的plugin.xml.请尝试重新添加.
任何的想法?