Ionic Notification has no sound - android

Look like there were some changes in Ionic Push Notification in the last few weeks.
OLD WAY
$ionicPush.register({
canShowAlert: true, //Can pushes show an alert on your screen?
canSetBadge: true, //Can pushes update app icon badges?
canPlaySound: true, //Can notifications play a sound?
canRunActionsOnWake: true, //Can run actions outside the app,
onNotification: function(notification) {
// Handle new push notifications here
alert(notification);
return true;
}
});
NEW WAY
$ionicPush.init({
"debug": true,
"onNotification": function(notification) {
var payload = notification.payload;
console.log(notification, payload);
},
"onRegister": function(data) {
console.log(data.token);
});
$ionicPush.register();
You can see that the different code in latest release preventing iOS from having sound and other features. I tried to add back canPlaySound: true in $ionicPush.init but it didn't work.
How do I get back the list of all notification features for ios?
UPDATE
Correct answer
$ionicPush.init({
"debug": true,
"onNotification": function(notification) {
var payload = notification.payload;
console.log(notification, payload);
},
"onRegister": function(data) {
console.log(data.token);
},
"pluginConfig": {
"ios": {
"badge": true,
"sound": true
},
"android": {
"iconColor": "#343434"
}
}
});

These are plugin options which I've added to our docs:
http://docs.ionic.io/docs/push-usage#section-plugin-options

Related

React Native PushNotification onNotification method

I am Getting notification from server. After receiving the notification, When I click on it, then again the same notification is coming. More I click on it more the notifications are coming.
My question is whether I am following the right approach in the above code? If not then please suggest me the correct one. How to handle the click of notification? So, that i can show the particular view on its click.
I'm using the following link
https://github.com/zo0r/react-native-push-notification
Thanks in advance :)
PushNotification.configure({
onNotification: function (notification) {
console.log('NOTIFICATION:', notification)
PushNotification.localNotification({
largeIcon: "ic_launcher",
title: notification.title,
message: notification.message,
});
},
senderID: "my sender ID",
popInitialNotification: true,
requestPermissions: true,
});
I have tried the following approach to solve this problem
PushNotification.configure({
onNotification: function (notification) {
console.log('NOTIFICATION:', notification)
const clicked = notification.userInteraction;
if (clicked) {
ToastAndroid.show(notification.message,ToastAndroid.CENTER);
} else {
PushNotification.localNotification({
largeIcon: "ic_launcher",
title: "Test",
//message: JSON.stringify(xyz.notificationResponse.bookingId),
});
}
ToastAndroid.show(notification.message,ToastAndroid.CENTER);
},
senderID: "your sender id",
popInitialNotification: true,
requestPermissions: true,
});

Application stops When receive a notification from Firebase Notifications

My application stops when you receive a notification, when the app is open, but when the application is not active, it receives 2 notifications.
Here is my initPushNotification():
initPushNotification(){
if(!this.platform.is('cordova')){
console.warn("Push notifications not initialized. Cordova is not available - Run in physical device");
return;
}
const options: PushOptions = {
android: {
senderID:"XXXXXXXXXXXX",
vibrate: true
},
ios: {
alert: "true",
badge: false,
sound: "true"
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('registration').subscribe((data:any)=>{
console.log("device token", data.registrationId);
//Here I send the device_token to my firebase database.
});
pushObject.on('notification').subscribe(()=>{
alert("new Message");
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error)); }

Ionic notification in android

I used blow code for ionic notification I have used fcm (firebase cloud messaging)
I Received push Notifications when the app is close but I didn't receive notification when the app is open(running) in android
app.js
.config(function($ionicCloudProvider) {
$ionicCloudProvider.init({
"core": {
"app_id": "xxxxxx"
},
"push": {
"sender_id": "xxxxxxxxxxxx",
"pluginConfig": {
"ios": {
"badge": true,
"sound": true
},
"android": {
"badge": true,
"iconColor": "#343434"
}
}
}
});
})
controler.js
$ionicPush.register().then(function(t) {
return $ionicPush.saveToken(t);
}).then(function(t) {
console.log('Token saved:', t.token);
alert(t.token);
});
$rootScope.$on('cloud:push:notification', function(data) {
console.log("dbhfd")
var msg = data.message;
console.log("dbhfd")
alert(msg.title + ': ' + msg.text);
$state.go('message');
});
use localnotification when new notification received in the foreground
this.fcm.onNotification().subscribe(data => {
if(data.wasTapped){
console.log("Received in background");
} else {
console.log("Received in foreground");
this.localNotifications.schedule({
id: 1,
title: ""+data.title+"",
text: ""+data.body+""
});
};
});
hi,
when the app is opened you will not get any notifications even you can check with Facebook or any other apps.if app is closed then only you will receive notifications that's not an issue i think you achieved your goal
If you want to integrate with firebase + push notifications then you can follow this link
here!
And in this push notifications link just keep register() function & related code in App.tsx then you will get notifications foreground and background.
And if you want to produce local notifications then follow this link here!

Ionic push notification is not working if app is open

I am able to send push form apps.ionic.io and from postman when app is on background or screen is locked but not able to send notification when app is open.
My code is as
in run
var io = Ionic.io();
var push = new Ionic.Push({
"onNotification": function(notification) {
alert('Received push notification!');
},
"pluginConfig": {
"android": {
"icon": "ic_stat_icon"
}
},
"debug": true
});
push.register(function(token) {
console.log("registered");
console.log("Device token:",token.token);
});
and in controller
$ionicPush.register( {
canShowconsole.log: true, //Can pushes show an console.log on your screen?
canShowAlert: true, //Can pushes show an alert on your screen?
canSetBadge: true, //Can pushes update app icon badges?
canPlaySound: true, //Can notifications play a sound?
canRunActionsOnWake: true, //Can run actions outside the app,
onNotification: function(notification) {
console.log(notification);
// Handle new push notifications here
alert('Received push notification!');
return true;
}
}).then(function(t) {
return $ionicPush.saveToken(t);
}).then(function(t) {
console.log('Token saved:', t.token);
});
Try this thing in your app.js or controller file.
$rootScope.$on('cloud:push:notification', function(event, data) {
var msg = data.message;
console.log(msg);
// alert(msg.title + ': ' + msg.text);
var alertPopup = $ionicPopup.alert({
title: msg.title,
template: msg.text.toString()
});
});

Ionic push notifications on Android doesn't register token on Ionic.io

I want to implement push notification on Android using ionic.
I've followed the documentation from Ionic push in a tutorial from devdactic Devdactic push notifications android I see with that example in the platform is saved a token.
I've make all settings that I need including GCM service and register user to ionic platform, but no token is registered.
I run app in emulator and user is registered but no token is saved. After some modifiers I receive a token in console but is not ok.
In example token is different and push does't work. Does someone have an working example with Ionic Push based on last documentation?
this is what I use to register pushes, it is messy but hopefully can be of some use. It checks if the current user is authenticated, if they aren't then it signs them up with a UUID (i used a UUID generator plugin) and saves the token. Just make sure your app is set up with Ionic.io and this should work :)
var user = Ionic.User.current();
if (user.isAuthenticated()) {
var push = new Ionic.Push({
"debug": true,
"onNotification": function (notification) {
},
"onRegister": function (data) {
console.log(data.token);
return true;
},
"pluginConfig": {
"android": {
"icon": "icon"
},
"ios": {
"badge": true,
"sound": true,
"alert": true
}
}
});
} else {
var uid = uuid2.newuuid();
var details = {
'email': uid + '#example.com',
'password': 'secretpassword'
};
Ionic.Auth.signup(details).then(function () {
var options = { 'remember': true };
Ionic.Auth.login('basic', options, details).then(function () {
user = Ionic.User.current();
user.set('uid', uid);
user.save();
var push = new Ionic.Push({
"debug": true,
"onNotification": function (notification) {
},
"onRegister": function (data) {
console.log(data.token);
return true;
},
"pluginConfig": {
"android": {
"icon": "icon"
},
"ios": {
"badge": true,
"sound": true,
"alert": true
}
}
});
push.register(function (token) {
console.log("Device token:", token.token);
push.saveToken(token);
});
}, function () { });
}, function () { });
}
In order to send push notification you need Api key and project number and current device id.
I think you are struggling in getting the user device id in order to get the current your device id please reffer ng-Cordova
you can find a line
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification)
in this you can see the notification parameter it is an object inside that object you can find regid field in that you can get your current device id this will be work on only mobile not on browser.
so in order to use that device id, for example lets assume your going to post a login form with divece id like given below.
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
console.log(event);
console.log(notification);
switch(notification.event) {
case 'registered':
console.log(notification.regid.length);
if (notification.regid.length > 0 ) {
// alert('registration ID = ' + notification.regid);
console.log('registration ID = ' + notification.regid);
var loginPost = {
"UserName":username,
"PassWord":password,
"DeviceID":notification.regid
};
console.log(loginPost);

Categories

Resources