I m Trying to send a push notification to IOS Device.
My code like that for send a notification to ios device.
if($db_to[0]['platform']=='1') {
$messagesArray[]=array(
'DeviceToken'=>$db_to[0]['device_id'],
'Message'=>$msg,
'Sound'=>'default',
'noti_status'=>$db_to[0]['noti_status'],
'Type'=>'1',
'pid'=>$Promotion[0]['pid'],
'rest_id'=>$Promotion[0]['rest_id'] ,
'pnm'=>$Promotion[0]['pname'] ,
'pimg'=>$Promotion[0]['pimage'] ,
'pdesc'=>$Promotion[0]['pdesc'] ,
'p_bk_img'=>$Promotion[0]['p_background_img'] ,
'p_d_img'=>$Promotion[0]['p_detail_img'] ,
);
}
In PHP side I got these type of array when I printed the $messagesArray array.
But in IOS side he/she was got the different response like that.
aps = {
alert = "sent you a Notification";
sound = default;
type = 1;
};
So my Question is that , is there any changes in to the apns file or dataservice api files ???
IOS got only Type and Sound , and Notification Message which one I Send.
they didn't get the whole response which I was print it my side.
so Guys Please help me.
How can I Solve these.
Thanks in advance.
yes, which parameters you want in response just pass all parameters in function..
Related
I am facing issue with Facebook Webhook for feed while messages are working perfectly. For one post i keep on getting multiple notification from Facebook. I have already raised a bug with Facebook and their team is saying that my server is failing to send back 200 OK HTTP status. Also in their doc i have found that
"Your webhook callback should always return a 200 OK HTTP response when invoked by Facebook. Failing to do so may cause your webhook to be unsubscribed by the Messenger Platform."
My code goes like this:
<?php
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];
if ($verify_token === 'password')
{
echo $challenge;
}
/*........RECEIVING INPUT FROM fACEBOOK.........*/
$input = json_decode(file_get_contents('php://input') , true);
error_log(print_r($input, true));
/*after this i am calling AI and then replying back*/
Is there any way to send back 200 OK status before calling AI in php.
For the Workaround, I have stored the notification in DB and for every notification i am checking existing data (timestamp, senderId, post) in the DB to eliminate the duplicate post.
If anyone is having better option in terms of complexity please let us know.
I a similar issue and in my case I was subscribed to my test app and actual production app. Thus 2 events being sent
I'm using a paid Pushwoosh Account in order to send programmatically push-notifications to my users.
I've implemented the Pushwoosh PHP SDK and everything works great, but I'm not able to set a Notification-Badge on iOS devices as seen on the following image:
My code so far is:
$devicesArr[] = ...
$pushwoosh = Pushwoosh::create()
->setApplication('79XXX-9CXXX')
->setAuth('Wkf...2C8');
//Create the Message
$request = CreateMessageRequest::create()
->addNotification(Notification::create()
->setContent('A new workout is available!')
->setDevices($devicesArr));
//Call the REST Web Service
$response = $pushwoosh->createMessage($request);
I tried to use the ->setBadge(5) method according to this page but this also does not work:
$request = SetBadgeRequest::create()
->setBadge(1)
->setHwid('18D...1AF');
Do you know how I can achieve my goal?
I can't reproduce this on Cordova Sample (https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample/tree/master/Phonegap-iOS-Android-WP), can you share a simple sample?
Are you sure the app is closed when you receive push with badge?
Per the docs, this is not the method you use to set the badge number on the device.
Important
This method IS NOT used to update the badge value on the device.
Instead please use /createMessage request with the "ios_badges" parameter.
http://docs.pushwoosh.com/docs/setbadge
I'm using codeigniter-gcm library on top of codeigniter to send messages to Google Cloud Messaging service. It sends the message and the message is received at the mobile device, but if I send multiple messages, only the latest message appears on the device (as if it is overriding the previous messages).
I'm seeing that I might need to create a unique notification ID, but I'm not seeing how it's done anywhere on the codeigniter-gcm documentation or Google's documentation for downstream messages.
Any idea how this should be done?
Here's my code in the codeigniter controller. It is worth mentioning that Google's response contains a different message_id for each time I send a push...
public function index() {
$this->load->library("gcm");
$this->gcm->setMessage("Test message sent on " . date("d.m.Y H:i:s"));
$this->gcm->addRecepient("*****************");
$this->gcm->setData(array(
'title' => 'my title',
'some_key' => 'some_val'
));
$this->gcm->setTtl(false);
$this->gcm->setGroup(false);
if ($this->gcm->send())
echo 'Success for all messages';
else
echo 'Some messages have errors';
print_r($this->gcm->status);
print_r($this->gcm->messagesStatuses);
}
After three exhausting days I found the solution. I'm posting it here in hope of saving someone else's time...
I had to add a parameter to the data object inside the greater JSON object, named "notId" with a unique integer value (which I chose to use a random integer from a wide range). Now why Google didn't include this in their docs? Beats me...
Here's how my JSON looks now, when it creates separate notifications instead of overriding:
{
"data": {
"some_key":"some_val",
"title":"test title",
"message":"Test message from 30.09.2015 12:57:44",
"notId":14243
},
"registration_ids":["*******"]
}
Edit:
I'm now thinking that the notId parameter is not really determined by Google, but by a plugin I use on the mobile app side.
To extend further on my environment, my mobile app is developed using Phonegap, so to get push notification I use phonegap-plugin-push which I now see in its docs that parameter name.
I'm kinda' lost now as far as explaining the situation - but happy it is no longer a problem for me :-)
You need to pass a unique ID to each notification. Once you have clicked on the notification you use that ID to remove it.
...
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.cancel(SIMPLE_NOTFICATION_ID_A);
...
But I'm sure you shouldn't have so much of notifications for user at once. You should show a single notification that consolidates info about group of events like for example Gmail client does. Use Notification.Builder for that purpose.
NotificationCompat.Builder b = new NotificationCompat.Builder(c);
b.setNumber(g_push.Counter)
.setLargeIcon(BitmapFactory.decodeResource(c.getResources(), R.drawable.list_avatar))
.setSmallIcon(R.drawable.ic_stat_example)
.setAutoCancel(true)
.setContentTitle(pushCount > 1 ? c.getString(R.string.stat_messages_title) + pushCount : title)
.setContentText(pushCount > 1 ? push.ProfileID : mess)
.setWhen(g_push.Timestamp)
.setContentIntent(PendingIntent.getActivity(c, 0, it, PendingIntent.FLAG_UPDATE_CURRENT))
.setDeleteIntent(PendingIntent.getBroadcast(c, 0, new Intent(ACTION_CLEAR_NOTIFICATION), PendingIntent.FLAG_CANCEL_CURRENT))
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
.setSound(Uri.parse(prefs.getString(
SharedPreferencesID.PREFERENCE_ID_PUSH_SOUND_URI,
"android.resource://ru.mail.mailapp/raw/new_message_bells")));
I am creating an android application where I need to send gcm messages.
So far I managed to get device id and to sent it to my server.
Now when I'm trying to push a message from my server to my app, I receive this message : {"multicast_id":4987023356709284342,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1430085972465424%73c650e3f9fd7ecd"}]}, but nothing happens on the device (doesn't matter if the app is running or not).
Here is my relevant code:
Manifest.xml----------------- AndroidManifest.xml
BroadcastReceiver-------- GcmBroadcastReceiver
IntentService---------------- GcmIntentService
Register---------------------- GcmRegister
here I am using the register class (look for 'GCM HERE' tag)
LoginActivity---------------- LoginActivity
here is my android project structure
Structure--------------------- structure
Server side [PHP]
GcmPush ------------------- GcmPush.php
and this is how I'm using GcmPush.php
SendMessage-------------- send function
Hope someone can help me.
To point what I'm doing wrong....
Thank you!
Finally I found...
I put logs in GcmReceive, and it prints the log :), then I went to IntentServices, and there I found that the message has arived but notification didn't actually notify the message.
So far I didn't found yet what the problem is with my notification but, I think is something wrong with this line :
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
I am glad that the biggest problem is solved. Now I am searching arround what I'm doing wrong with Notification.
Thanks very much to everyone who tried to help...
Kindly refer the tutorial of GCM here. According to me you are missing the configuration file of GCM which has the APP_SERVER_URL, GOOGLE_PROJECT_ID.
This is an effort to develop a Android application which enable C2DM
Things I have done correctly
Get a valid Gmail address with C2DM
Write an Android app for getting a registrationId from C2DM
Get that registrationId from C2DM
Pass that registrationId to the third party server (I sent to a php
page) (1)
Send it correctly (I checked it with the HttpEntity class in the same
android app and I got the content of that page)
Getting Google authentication ID in server side (used PHP)
Open a Gmail account in my emulator (Menu - Settings - Accounts & sync - Add acount)
Things I am confused
How that web page (1) get notified when my Android app passed a "http" request?
How can I display the registrationId in the web page which sent by my Android app?
Things that wont work
Sending PushNotification to the emulator which runs my Android app. Referred this. That code is really good and first part also woks for me. But when I run the sendMessageToPhone() function it sends me 401. In my code I hard coded the values for;
$authCode = Google authentication code I get
$deviceRegistrationId = Code sent by the C2DM to my Android app
So please help me to clear my confusions and to correct my "wont work" activities.
Here is a simplest code for sending POST request to PHP:
String url = "http://your.domain.com/path/to/your/post/request/handler.php";
HttpClient client = new DefaultHttpClient();
try {
List<NameValuePair> post = new ArrayList<NameValuePair>();
post.add(new BasicNameValuePair("registrationId", "[YOUR ID VALUE HERE]"));
client.setEntity(new UrlEncodedFormEntity(post));
client.execute(new HttpPost(url));
} catch(IOException e) {
//do something here
}
On server side(i.e. in your PHP script) you can use $_POST superglobal variable which is populated from POST data and it's a simple associative array. Something like this:
if (!empty($_POST['registrationId'])) {
//do something here
}