Hello im trying to send a windows phone 8 push notification that is working in ios and android environment, but in my windows phone cell doesnt recieve.
In my worklightconsole ive seen that the user is suscribe and the push is send.
this is my custom configuration for windows phone environment
application-descriptor.xml:
<windowsPhone8 version="1.0" securityTest="xxxxxxxxxx-strong-mobile-securityTest">
<uuid>xxxxxxxxxxxxxxxxxxxxxxxxxxx</uuid>
<pushSender />
</windowsPhone8>
WL adapter code:
try {
var usuario = "9136";
var usuariosNoEncontrados = 0;
// var cantUsuarios = usuarios.length
try {
var badgeDigit = 1;
var notification = WL.Server.createDefaultNotification(mensaje, badgeDigit, {custom:"data"});
notification.MPNS.raw = {
payload : {payload : "You have a meeting in 5 minutes"}
};
var userSubscription = WL.Server.getUserNotificationSubscription(
'Fiesta2015_PUSH_NOTIFICATIONS.FiestaEventSource', usuario);
if (userSubscription != null) {
WL.Server.notifyAllDevices(userSubscription, notification);
} else {
WL.Logger
.info("User not found:: "
+ usuario);
}
return {
codigo : "0",
error : "",
respuesta : "OK"
};
} catch (e) {
return {
codigo : "2",
error : e,
respuesta : ""
};
}
} catch (e) {
// TODO: handle exception
return {
codigo : "2",
error : e,
respuesta : ""
};
}
trace in my developer server
[10/2/15 15:04:52:732 GMT-03:00] 0000040a com.ibm.pushworks.server.notification.mpns.MPNSSender E FPWSE1028E: Notification through Microsoft Push Notification Service (MPNS) to subscription 'http://s.notify.live.net/u/1/bn1/H2QAAACeRdLTzN62GukR6VNR79CH16nLA287g3zW2jmMAKEM7yA2YQcWSrJJbBBd7ma0MjJqB4Za0hceofRW258O2kqxVikHilukxiiThqkCI6JNGeXldHH2RZPutOv_qL2EM94/JHtzZXJ2aWNlbmFtZX0/Y6WgLTaz-ESHoQtbNpQ2HQ/S7AyIDdrf4nCanHvc95MA4wyO90' was not delivered (reason: 's.notify.live.net')
java.net.UnknownHostException: s.notify.live.net
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
at java.net.InetAddress.getAllByName0(InetAddress.java:1246)
at java.net.InetAddress.getAllByName(InetAddress.java:1162)
at java.net.InetAddress.getAllByName(InetAddress.java:1098)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:44)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:259)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:159)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:131)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at com.ibm.pushworks.server.notification.mpns.MPNSSender.sendAndVerify(MPNSSender.java:241)
at com.ibm.pushworks.server.notification.mpns.MPNSMediator.sendOrWait(MPNSMediator.java:88)
at com.ibm.pushworks.server.notification.mpns.MPNSMediator.sendNotification(MPNSMediator.java:80)
at com.ibm.pushworks.server.notification.Mediator$2.run(Mediator.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Which configuration im missing.
When application is in background only toast and tile notifications are applicable on Windows Phone 8.
a) To get Toast notifications , modify the adapter code:
notification.MPNS={};
notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});
//Set Toast notification for MPNS
notification.MPNS.toast={};
notification.MPNS.toast.text1 = "Toast title";
notification.MPNS.toast.text2 = "Toast content";
b) For tile notifications, pin the application to the start screen.
Related
I'm working with react native and firebase 6 to send push notifications.
I use the official documentations of the new version :
https://invertase.io/oss/react-native-firebase/v6
I add native code for both android and ios to handle sending and receiving notifications
In my AndroidManifest.xml :
<!-- [START firebase_service] -->
<service
android:name=".java.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_service] -->
I did not create the MyFirebaseMessagingService .
I AppDelegate.m i add some functions :
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[FIRMessaging messaging].APNSToken = deviceToken;
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
NSLog(#"APNs device token retrieved: %#", deviceToken);
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
NSLog(#"Unable to register for remote notifications: %#", error);
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
}
In my Component.js i get the token like this :
// Firebase
import firebase from '#react-native-firebase/app'
import messaging from '#react-native-firebase/messaging'
// ----- COMPONENT DID MOUNT ---- //
async componentDidMount () {
// ====================================================== //
// ====================================================== //
// ====================================================== //
const granted = messaging().requestPermission()
if (granted) {
console.log('User granted messaging permissions!')
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
firebase
.messaging()
.getToken()
.then(fcmToken => {
if (fcmToken) {
// user has a device token
console.log('-------- FCM TOKEN -------')
console.log(fcmToken)
console.log(JSON.stringify(fcmToken))
this._setItem(fcmToken)
} else {
// user doesn't have a device token yet
console.log('error')
}
})
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
} else {
console.log('User declined messaging permissions :(')
}
// ====================================================== //
// ====================================================== //
// ====================================================== //
}
// ----- FIN COMPONENT DID MOUNT ---- //
I send POST request to https://fcm.googleapis.com/fcm/send :
{
"to" : "token",
"notification" : {
"body" : "un nouveau partage",
"title" : "un partage de contact reçu",
"priority" : "high",
"vibration":true,
"sound": "Enabled",
"badge":1,
"requireInteraction": true,
"click_action": "fcm.ACTION.HELLO"
},
"data" : {
"body" : "nouvelle opportunité",
"title" : "un nouveau partage",
"content_available" : true,
"priority" : "high"
}
}
I receive the notification for both android and ios but i can't handle the click action :
I want to redirect to specific route when the user click on the notification .
I haven't used Firebase for notifications, but as you're saying the notifications are working, then the actual issue it seems to me is you want to handle it when your app opens.
So here are the steps you have to follow to get your work done.
Get the data coming in the notification, on the event onNotificationOpened. Check out this link to check if you're getting the notification data.
Next, you want to a specific route on the basis of notification. What I do is, send the type of the screen and id related to that screen to navigate there, ex:
{
"entity": "Place",
"id": "123"
}
So, when I receive the notification, I send the data to a switch case factory that navigate to the screen on the basis of info in that data. Something like that.
function navigateToScreen(entity:string, id:string){
let screenName = "";
let params = {}
switch(entity){
case "Place":
screenName = "placeScreen";
params = {id};
break;
default: return;
}
// Navigation Service = https://reactnavigation.org/docs/navigating-without-navigation-prop/
NavigationService.navigate(screenName, params);
}
Now in case you want to run a specific function on the basis of notification, you can do it on the basis of info received. Like in this example I have to make an API req to get the data of that place by id.
const id = props.match.params['id'];
useEffect(() => {
getThePlaceDetails(id);
}, [id]);
I am able to send Push notifications using the code below but I am also required to associate "Conversion events" with the notification. This can be done through the console but I couldn't find how to do it with SDK.
var message = new Message()
{
Data = new Dictionary<string, string>()
{
{ "test1", "6165" },
{ "test2", "161" },
},
Notification =
{
Body = "",
Title = ""
},
Topic = topic,
};
// Send a message to the devices subscribed to the provided topic.
Task<string> response = FirebaseMessaging.DefaultInstance.SendAsync(message, true);
// Response is a message ID string.
response.Wait();
Console.WriteLine("Successfully sent message: " + response);
Working on an app that has two parts - Rider & Driver. When the driver accepts the request, an alert is then sent to the rider that the request was accepted and driver is on the way.
Unable to trigger the alert to the rider.
RiderVC:
func driverAcceptedRequest(requestAccepted: Bool, driverName: String) {
if !riderCancelledRequest {
if requestAccepted {
self.alertTheUser(title: "Ryde Accepted", message: "\(driverName) Has Accepted Your Ryde Request and will message you with details")
} else {
RydeHandler.Instance.cancelRyde()
alertTheUser(title: "Ryde Cancelled", message: "\(driverName) Has Cancelled the Ryde Request")
}
}
riderCancelledRequest = false
}
RydeHandler.swift:
// DRIVER ACCEPTED RYDE
DataService.Instance.requestAcceptedRef.observe(FIRDataEventType.childAdded) { (snapshot: FIRDataSnapshot) in
if let data = snapshot.value as? NSDictionary {
if let name = data[Constants.NAME] as? String {
if self.driver == "" {
self.driver = name
self.delegate?.driverAcceptedRequest(requestAccepted: true, driverName: self.driver)
}
}
}
}
Firebase database structure:
Edit
ViewDidLoad in tableviewcontroller - list of requests:
ref.child("drivers").child("RideRequests").observe(FIRDataEventType.value, with: { snapshot in
self.rideRequests.removeAll()
for item in snapshot.children{
self.rideRequests.append(item as! FIRDataSnapshot)
}
self.rideRequests.reverse()
self.tableView.reloadData()
})
does this get triggered again from the server containing a message?
"ecb":"window.onNotificationGCM"
I have this set up on the server
device_tokens = [], //create array for storing device tokens
retry_times = 4, //the number of times to retry sending the message if it failed
sender = new gcm.Sender('AIzaSyDpA0b2smrKyDUSaP0Cmz9hz4cQ19Rxn7U'), //create a new sender
message = new gcm.Message(); //create a new message
message.addData('title', 'Open Circles');
message.addData('message', req.query.message);
message.addData('sound', 'notification');
message.collapseKey = 'testing'; //grouping messages
message.delayWhileIdle = true; //delay sending while receiving device is offline
message.timeToLive = 3; //the number of seconds to keep the message on the server if the device is offline
device_tokens.push(val.deviceToken);
sender.send(message, device_tokens, retry_times, function(result){
console.log(result);
console.log('push sent to: ' + val.deviceToken);
});
So what I want to know is, once a server call is made will it trigger the notification on the front. What am I missing about this system?
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if (event.foreground) {
console.log('INLINE NOTIFICATION');
var my_media = new Media("/android_asset/www/" + event.soundname);
my_media.play();
} else {
if (event.coldstart) {
console.log('COLDSTART NOTIFICATION');
} else {
console.log('BACKGROUND NOTIFICATION');
}
}
navigator.notification.alert(event.payload.message);
console.log('MESSAGE -> MSG: ' + event.payload.message);
//Only works for GCM
console.log('MESSAGE -> MSGCNT: ' + event.payload.msgcnt);
//Only works on Amazon Fire OS
console.log('MESSAGE -> TIME: ' + event.payload.timeStamp);
break;
case 'error':
console.log('ERROR -> MSG:' + event.msg);
break;
default:
console.log('EVENT -> Unknown, an event was received and we do not know what it is');
break;
}
};
return {
register: function () {
var q = $q.defer();
if(ionic.Platform.isAndroid()){
pushNotification.register(
successHandler,
errorHandler,
{
"senderID":"346007849782",
"ecb":"window.onNotificationGCM"
}
);
}else{
pushNotification.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"window.onNotificationAPN"
}
);
}
return q.promise;
}
}
update. Eventually my server spit back this: TypeError: Cannot read property 'processIncomingMessage' of undefined
It seems my google ID was not working. I created a new one and now it's sending push requests.
I have been trying to get Push notifications working for an android application. When the app is focussed, the push is received just fine. However, when the application is in the background, i see an error in the log.
My code is -
var CloudPush = require('ti.cloudpush');
CloudPush.retrieveDeviceToken({
success: function deviceTokenSuccess(e) {
console.log('Device Token: ' + e.deviceToken);
token = e.deviceToken;
that.token=token;
},
error: function deviceTokenError(e) {
console.log('Token Error: ' + e.error);
}
});
CloudPush.debug = true;
CloudPush.focusAppOnPush = false;
CloudPush.enabled = true;
// CloudPush.showAppOnTrayClick = false;
CloudPush.showTrayNotification = true;
// CloudPush.singleCallback = true;
CloudPush.addEventListener('callback', function(evt){
alert('A push notification was received!');
console.log('A push notification was received!' + JSON.stringify(evt));
});
CloudPush.addEventListener('trayClickLaunchedApp', function(evt){
alert('A push notification was received - onLaunched');
console.log('A push notification was received!' + JSON.stringify(evt));
});
CloudPush.addEventListener('trayClickFocusedApp', function(evt){
alert('A push notification was received - onFocused');
console.log('A push notification was received!' + JSON.stringify(evt));
});
and the error i am receiving is -
07-18 14:19:44.853: E/TiApplication(25319): (main) [9,46101] Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to start receiver ti.cloudpush.GCMReceiver: java.lang.NullPointerException; Titanium 3.2.3,2014/04/22 10:17,b958a70
07-18 14:19:44.853: E/TiApplication(25319): java.lang.RuntimeException: Unable to start receiver ti.cloudpush.GCMReceiver: java.lang.NullPointerException
Any thoughts on how i could work this out is highly appreciated.
Im using Titanium SDK - 3.2.3 GA.