1

I am in the process of writing my first Android Cordova app using OneSignal for Push notifications. The process of setting up OneSignal and enabling Cloud Messaging on Google turned out to be remarkably easy. With that done I proceeded to create a simple jQuery Mobile Cordova app and modified the init function app.js

function init() 
{
 window.plugins.OneSignal.setLogLevel({logLevel:4,visualLevel:4});
 var notificationOpenedCallback = function(jsonData) {
  alert(JSON.stringify(jsonData));
 window.plugins.OneSignal.enableVibrate(true);
 window.plugins.OneSignal.enableSound(true);

};

window.plugins.OneSignal.init('one-signal-id', {googleProjectNumber: 'project no'}, notificationOpenedCallback); }

Having built the APK I installed it on my Android device and got two INFO messages - one from Google and one from OneSignal. I am assuming that this is because I have a debug build with the loglevel set to 4.

I then proceeded to send out a push via OneSignal. The message appears in the Sent messages list. However, nothing whatsoever happens on my phone - I had expected it to vibrate at the very least.

Also, I would like to hook into the notificationOpened event. It is not clear from the OneSignal docs how this should be done. I am into my first hour with OneSignal and push notifications so I am assuming that I am overlooking something here. I'd be grateful to anyone who might be able to put me on the righ track.

4

1 回答 1

1

如果您的应用程序处于焦点状态,则默认情况下不会显示通知。您可以通过将enableNotificationsWhenActive设置为 来更改此设置true

OneSignal Cordova 设置指南中的步骤 2.1显示了在打开通知时设置回调处理程序。

var notificationOpenedCallback = function(jsonData) {
  console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
};

window.plugins.OneSignal.init("b2f7f966-d8cc-11e4-bed1-df8f05be55ba",
                               {googleProjectNumber: "703322744261"},
                                notificationOpenedCallback);

的结构与一些示例一起jsonData记录在notificationOpenedCallback中。

于 2016-04-21T19:08:43.083 回答