Closed Alainzz closed 9 years ago
This kind of logic would need to be implemented on the server side, wherever you are controlling your push notifications from.
You can target users directly via their device tokens, so you can send a notification to whichever devices you want.
Hi
Sorry but it Is not a good answer for me HOW CAN I DO ?? PLEASE
Thank You your help Best regards Alain
-----Message d'origine----- De : "koriner" notifications@github.com Envoyé : 29/10/2014 10:25 À : "distriqt/airnativeextensions" airnativeextensions@noreply.github.com Cc : "Alainzz" alain2003fr@yahoo.fr Objet : Re: [airnativeextensions] PushNotification to multi users (#259)
This kind of logic would need to be implemented on the server side, wherever you are controlling your push notifications from. You can target users directly via their device tokens, so you can send a notification to whichever devices you want. — Reply to this email directly or view it on GitHub.=
Hi Alainzz, it is possible. I do it perfectly with Distriqt ANE.
I assume you want to send PUSH notification, for that you need to do the followoing:
This is just brief explanation so you get idea of how it works.
p.s. Remember that one user can have multiple devices so it could be more that 1 PUSH-TOKEN per user.
p.s.s. And don't forget to obtain proper certificates from you Apple Dev Account to send PUSH notifications.
Best regards, Max
@Alainzz Max is exactly right, I just wanted to add a few things.
This is not something that can be done "safely" from the device but something that you should integrate into your application server.
The implementation will need to be split based on the destination user's device i.e. you'll need to use APNS to send notifications to iOS and GCM to Android, so you'll have to take into account whether the user is on Android or iOS or event whether your application allows interaction between the platforms.
Cheers, Michael
Hello minimedj,
Thank you a lot for your explanation. My problem is.
1) How can I take the user token 2) How send push with this toke
Do you have a little sans source please ? Exemple currenly for Android I send a Push Notification with this PHP script Where can I modify my script for add the device token of the user A to be sur to send it to user A
<?php
/**
php simplepush.php
/// Message to send $message = "the test message"; $tickerText = "ticker text message"; $contentTitle = "content title"; $contentText = "content body";
// Put your device token here (without spaces): $registrationId = '???????????????????????????????????????????????????????????????????';
// GCM API Key $apiKey = "????????????????????????????????????????????????????????????????"; $sound='default';
$response = sendNotification( $apiKey, array($registrationId), array('message' => $message, 'tickerText' => $tickerText, 'contentTitle' => $contentTitle, 'sound' => $sound, 'contentText' => $contentText) );
echo $response; echo "\ncomplete...\n";
////////////////////////////////////////////////////////////////////////////////
//
//
/**
@param $messageData [array] An named array of data to send as the notification payload */ function sendNotification( $apiKey, $registrationIdsArray, $messageData ) { print_r($messageData);
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey); $data = array( 'data' => $messageData, 'registration_ids' => $registrationIdsArray );
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send" ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($data) );
$response = curl_exec($ch); curl_close($ch);
// error_log(json_encode($data)); // error_log($response);
return $response;
}
Thank you a lot for your help
@Alainzz I won't answer you about server side because your question is about php. I am not expert in php, I am expert in Erlang. Anyways it must be very simple curl request to PUSH server. I believe you will find a way to handle it. Just remember - you need to obtain proper certificates from iTunes (in case you use iOS, I have to experience with Android).
This is my helper class that does all stuff with PUSH (I removed code that not related to this subject but this is pretty much everything you need to do ti handle PUSH stuff):
package utils {
import com.distriqt.extension.pushnotifications.PushNotifications;
import com.distriqt.extension.pushnotifications.events.PushNotificationEvent;
import starling.events.EventDispatcher;
/**
* Push Notification Manager
*/
public class PushNotificationManager extends EventDispatcher {
/**
* Shows system "Enable Push Notifications" popup.
*/
public static function showEnablePushNotificationsPopup():void {
try {
if (PushNotifications.service.getDeviceToken() == "")
PushNotifications.service.register("GCM_SENDER_ID"); // note <-- replace me with google gcm id
} catch (e:Error) {
trace(e.message + "\n" + e.getStackTrace());
}
}
public static function init():void {
try {
PushNotifications.init(Settings.DISTRIQT);
if (PushNotifications.isSupported) {
PushNotifications.service.addEventListener(PushNotificationEvent.REGISTER_SUCCESS, registerSuccessHandler);
PushNotifications.service.addEventListener(PushNotificationEvent.UNREGISTERED, unregisteredSuccessHandler);
PushNotifications.service.addEventListener(PushNotificationEvent.NOTIFICATION, notificationHandler);
PushNotifications.service.addEventListener(PushNotificationEvent.ERROR, errorHandler);
PushNotifications.service.register("GCM_SENDER_ID");
}
} catch (e:Error) {
trace(e.message + "\n" + e.getStackTrace());
}
}
private static function registerSuccessHandler(event:PushNotificationEvent):void {
trace("PN registration succeeded with reg ID: \n" + event.data);
// save push_key on server
}
private static function unregisteredSuccessHandler(event:PushNotificationEvent):void {
trace("PN un-registration succeeded");
// remove push_key from server
}
private static function notificationHandler(event:PushNotificationEvent):void {
trace("Remote notification received");
try {
// here you handle PUSH notification
var obj:Object = JSON.parse(event.data);
} catch (e:Error) {
trace("ERROR:: " + e.message);
}
}
private static function errorHandler(event:PushNotificationEvent):void {
// do nothing
trace("ERROR:: " + event.data);
}
}
}
You have to call PushNotificationManager.init();
somewhere it the start of you app.
I just copied it from my sources. It work just fine for me.
Hello minimedj,
Thank for your source but I think it's the same to me your it's for IOS me for Android But when you send a push with your souce your send for ALL user right ? Me I would like to send a Push for ONE user exemple User A tomorrow to user B etc..
Could you explain me how can I do please ?
Really thank you a LOT for your help minimedj
Best regards
@Alainzz it seems for me that do not understand basics of PUSH technology. The source I provided is ActionScript - so it runs on client, there is nothing about sending PUSH notifications. To send PUSH notification you need your server.
Please watch this video to get idea of how it works: https://www.youtube.com/watch?v=ATYhOlK11QM
Hello It's terrible for me you dont understant my request.My pushnotification WORK correctly I would like juste know if it's possible to send a push for a particular user do you understand me ? please.............................. Application USER AP A AP B AP C I would like in my server send a push notification to A. and other day I would like to send a push notification to B and other day I would like to send a push notification to A and B etc... I hope this times you understand me Thank you for your help Best regards
@Alainzz I already told you how to do it.
Application USER PUSH-TOKEN
---------------------------------
AP A Token-A
AP B Token-B
AP C Token-C
To send PUSH notification to user A you use Token-A To send PUSH notification to user B you use Token-B etc...
Do you understand that for each user you have to save it's PUSH-TOKEN?
OK if I understand but again how can I do in my server to send only for an user A or B with token ? The token is special device right ?
sorry It's not clean
Thank you for you help
@Alainzz We can't really help you with your server side code since we don't know how it works.
Basically you would just need to query your database to find whichever users you want to send the notification to, and then select their device tokens - which you then use when you make the request to send push notifications from APNS or GCM.
I understand now ;) We can close the case Thank you very VERY mutch for your help
Best regards
Hello,
About Android and IOS is it possible to send a notification by user for one application ? If yes how can I do please ?
Exemple: I have an application A installed in mobile user A1 and user A2 and user A3 I would like send a notification to only user A1 or only user A2 and A3 etc...
Thank you for your help