Closed argum closed 2 years ago
I forgot to add the app code:
// Import core module
var core = require('firebase.core');
// Configure core module (required for all Firebase modules).
core.configure();
// Important: The cloud messaging module has to imported after (!) the configure()
// method of the core module is called
var fcm = require('firebase.cloudmessaging');
// Called when the Firebase token is registered or refreshed.
fcm.addEventListener('didRefreshRegistrationToken', function(e) {
callbackForRegisterPushNotifications({success: true, deviceToken: e.fcmToken});
Ti.API.error('didRefreshRegistrationToken', e.fcmToken);
});
// Called when direct messages arrive. Note that these are different from push notifications.
fcm.addEventListener('didReceiveMessage', receivePush);
//fcm.notificationChannel = androidCreateNotificationChannel();
fcm.createNotificationChannel({
sound: 'warn_sound',
channelId: 'default',
channelName: 'General Notifications',
importance: 'high'
});
// display last data:
//Ti.API.error("Last data: " + fcm.lastData);
// Check if token is already available.
if (fcm.fcmToken) {
Ti.API.error('FCM-Token', fcm.fcmToken);
callbackForOnReceivePush({success: true, deviceToken: fcm.fcmToken});
} else {
Ti.API.error('Token is empty. Waiting for the token callback ...');
}
// Subscribe to a topic.
fcm.subscribeToTopic(declara.pushTopic);
please use the preview tab when you post issues. I've corrected your code block again. Use ```
for multi line code blocks!
The interesting part would be your php push part. Since the data arrives when the app is open that part works. Try sending a notification message (that one is handled by the system) to see if it works in the background.
Thanks, m1ga. I will use preview before post a message.
Regarding "try sending a notification message (that one is handled by the system), what do you mean?
The PHP code performs the following one:
curl -X POST -H 'Authorization: key=AUTH_KEY' -H 'Content-Type: application/json' --data '{"to":"\/topics\/d2app_es","data":{"data":{"alert":"ESFCM & APNS notification","android":"{\"style\": {\"type\": \"big_picture\",\"big_picture\": http:\/\/d2webpau.iit.idisc.es\/site1\/images\/1509?w=195&h=195,\"title\": \"Testing title\",\"summary\": \"Testing summary\"}}","title":"d2app - liti","vibrate":[100,50,50,50,100],"badge":0,"tag":"APP","sound":"default","icon":"http:\/\/d2webpau.iit.idisc.es\/site1\/images\/1509?w=195&h=195","type":"M"}}}' https://fcm.googleapis.com/fcm/send 2>&1
your payload looks wrong. This curl works fine for me:
curl -XPOST https://fcm.googleapis.com/fcm/send -H 'Authorization: key=AUTH_KEY' -H 'Content-Type: application/json' --data '{
"to":"/topics/d2app_es",
"data":{"alert":"ESFCM & APNS notification","title":"d2app"}
}'
https://github.com/hansemannn/titanium-firebase-cloud-messaging#sending-push-messages
Hello to all.
On android devices, I am not able to create the notification alert, neither if the app is in background, closed, or open.
What I expect is to get a notification when the app is closed or in background.
If the app is opened and I send a push throught PHP, "didReceiveMessage" event is called.
Console throws some warn messages after didReceiveMessage is called:
[WARN] : ConnectionTracker: Exception thrown while unbinding [WARN] : ConnectionTracker: java.lang.IllegalArgumentException: Service not registered: com.google.android.gms.measurement.internal.zzjr@214bb0a [WARN] : ConnectionTracker: at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1289) [WARN] : ConnectionTracker: at android.app.ContextImpl.unbindService(ContextImpl.java:1483) [WARN] : ConnectionTracker: at android.content.ContextWrapper.unbindService(ContextWrapper.java:648) [WARN] : ConnectionTracker: at com.google.android.gms.common.stats.ConnectionTracker.zza(com.google.android.gms:play-services-basement@@17.3.0:55) [WARN] : ConnectionTracker: at com.google.android.gms.common.stats.ConnectionTracker.unbindService(com.google.android.gms:play-services-basement@@17.3.0:50) [WARN] : ConnectionTracker: at com.google.android.gms.measurement.internal.zziz.zzah(com.google.android.gms:play-services-measurement-impl@@17.3.0:248) [WARN] : ConnectionTracker: at com.google.android.gms.measurement.internal.zziz.zzam(com.google.android.gms:play-services-measurement-impl@@17.3.0:265) [WARN] : ConnectionTracker: at com.google.android.gms.measurement.internal.zziz.zzc(com.google.android.gms:play-services-measurement-impl@@17.3.0:332) [WARN] : ConnectionTracker: at com.google.android.gms.measurement.internal.zzjc.zza(com.google.android.gms:play-services-measurement-impl@@17.3.0:2) [WARN] : ConnectionTracker: at com.google.android.gms.measurement.internal.zzai.run(com.google.android.gms:play-services-measurement-impl@@17.3.0:7) [WARN] : ConnectionTracker: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) [WARN] : ConnectionTracker: at java.util.concurrent.FutureTask.run(FutureTask.java:237) [WARN] : ConnectionTracker: at com.google.android.gms.measurement.internal.zzgn.run(com.google.android.gms:play-services-measurement-impl@@17.3.0:21)
didReceiveMessage argument: {"type":"didReceiveMessage","source":{"fcmToken":"cNmCg_z2S9yeXRkwVSUTFc:APA91bEKYCK6CtndLRhza6q23O_JkcZqmld2QfJaIVTVo6s5zTQpGp4Xhw60t0V1EH1Q-kKuDTjzN38U9bsZZo8o9vlQiSR4Qn71pMpGimvzcOuFk5TPlNE5G9sv9LUU4Qrp7Ncr0LEY","forceShowInForeground":false,"lastData":{"inBackground":true,"fullscreen":false,"message":{"data":"{\"badge\":0,\"alert\":\"d2App\",\"sound\":\"default\",\"icon\":\"R\",\"vibrate\":[100,50,50,50,100],\"tag\":\"APP\",\"title\":\"adsadaa\"}"}},"apiName":"Ti.Module","bubbleParent":true,"invocationAPIs":[],"_events":{"didRefreshRegistrationToken":{},"didReceiveMessage":{}}},"message":{"messageType":null,"data":{"data":"{\"badge\":0,\"alert\":\"d2App\",\"sound\":\"default\",\"icon\":\"R\",\"vibrate\":[100,50,50,50,100],\"tag\":\"APP\",\"title\":\"adsadaa\"}"},"to":null,"sendTime":1602069681974,"from":"623396497913","messageId":"0:1602069681987646%61ff0399f9fd7ecd","ttl":2419200},"bubbles":false,"cancelBubble":false}
Thanks again!