Is possible to send an iOS push notification to a specific device? I've built a forum type app which the user can create a question and other people can answer it. I need to send an iOS Push Notification to the specific user which asked the question informing them that the question was answered. Is this possible to be done through PHP or another method?
Yes, you can absolutely send a push notification to a specific device.
First you need to ask the device for permission to receive push notifications:
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
Then if the user accepts you will receive the delegate message didRegisterForRemoteNotificationsWithDeviceToken. You then pass that deviceToken to your server with the user Id from your app that identifies the user in your forum. Something like this:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
NSString* deviceToken = [[[[_deviceToken description]
stringByReplacingOccurrencesOfString: #"<" withString: #""]
stringByReplacingOccurrencesOfString: #">" withString: #""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
//send deviceToken and your userId to your server to associate the two together
}
Then you need to build your push server which sends the notifications, which I won't get into here as there is a ton of documentation online for that and it is quite involved. You can also use third party services for this such as Urban Airship and StackMob.
When you send push notification, the device gets an unique ID which you use to send to Apple to tell them whom to deliver the message to.
When you get this unique ID you send it off to your server, when you do that you can include any other data such as username, refs ect.
Its more of a server-side issue than an iOS issue.
Mateus,
tl;dr: Yes, you can.
Since your forum app is written in php, here are some frameworks that may be useful to you:
http://www.easyapns.com/
http://code.google.com/p/apns-php/
If you end up using Easy APNS:
You can send messages to a single user (like in your example), or to a group of users (maybe everyone who is "watching" that thread) using an array of user identifiers. Quite a few examples are available here: https://github.com/manifestinteractive/easyapns/blob/master/src/php/samples.php
Sure, there are a lot of free Push Notification servers - for example QuickBlox
You don't need any server code, QuickBlox already wrote all for you.
Just look at Push Notifications iOS sample - This sample enables you to send notifications and alerts to particular user or group of users at any time through an API or easy-to-use admin panel.
Just download it, move some code from it to your app - and enjoy it.
Related
I am creating an web app and a user can start a game with multiple players (your friends). This game is played on 1 device. Is it possible that all invited players get a notification on their device where they can accept or decline the invitation ?
So in steps
Player 1 creates a game and invites player 2 and 3
Player 2 receives a notification on his mobile device and presses accept, he is added as player of that game
Player 3 doesn't have a device and enters his PIN to accept his participation.
The step that I want to have is step2.
I have read about OneSignal who can send push notifications to specific users, but I could not find if you can send a response back (accept or decline). Or is there an other way (without to have a native app).
your question is understood but at this moment a little too broad. But. I will try to answer in concept also :)
Now...you said you already know how to send target specific notification with OneSignal.
What you need to do from now one it cloud be like this:
Attach a link or click or action to that invite. Or when such invite
arrived open a particular view in the app/web/application that you are developing and revives the link.
Attach the session/game/user/object ID to that link and send the call
to you API (which is based on your server). If you have an API, if you don't you can have a very simple API build to handle only such requests with URL xxxx.com/path/to/api/call/var1/var2/var3/etc
From there you can catch the request and reply or adapt accordingly on your server side.
Maybe this Framework can help you to speed up the API dev in PHP. Lumen can do that trick.
You can follow this tutorial here for a fast API development with it.
We have firebase chat application (check any chat example or tutorial) that will have same copy as our.
We would like to sent email notification or sms message, if user hasn't seen the chat message yet.
We can connect to firebase database with php and check all the messages, if they are seen or not. but It's not really proper way of doing it.
Does anyone have idea how we can implement that, so we can track of all the messages and if they haven't seen it, then sent the email / sms notification based on user preference?
I just want to know how we can do that with firebase. if it was just php and mysql. it was really easy to do this.
Not sure if this can be done efficiently in Firebase. You will have to setup a cron job to fetch the messages which are not seen and trigger SMS/Email fallback.
I would recommend using Applozic (https://www.applozic.com) for Chat related stuff and Firebase for storing user meta data and other data.
Applozic provides a single click configuration to enable Webhook/SMS/Email fallback, along with that you will get all the whatsapp like chat features along with full UI with no need to write any additional code.
I'm trying to implement push notification but I'm a little bit lost.
I just want to have a button in php and when I click it, a notification appear in all devices telling the users something like: "A new image is available in the web".
I read the GCM documentation but I'm not sure how to start.
I see that in some examples the users have to send their emails in order to register their "sender id"? it is necessary? I want the user don't have to register anywhere.
Can someone help me to start or give me a quick tutorial?
Thank's for all.
You will need to use curl to call the GCM, you can find examples like this all over SO, for example : how to send a notification to millions of android devices in php using GCM (first one that came up in a search)
And of course you will need the registration id's otherwise GCM doesznt know which device to send the notification to.
The solution is not so simple. You should at least use some package dedicated to this specific service. Also, you should read something about what push notifications are.
There are many services out there you can use to interface yourself with this specific kind of service.
Take a look to this service to get a first idea about the entire mechanism. Remember that you have to subscribe to a push service provider for every platform you want to use. For example the Apple Push Notification Service, or Cloud Messaging by Google.
Hope it's a good start for you.
I am wondering if it is possible to send push notifications to different Android applications. I can already send a push notification in same application but I want to send notification to different applications of mine. I have user application and driver application. I need to send push notification when user create order and driver get notification that "A new order is come" after driver accept. Acknowledgement notification get back to user.
I am using two different Google API for both Application, I think, its not good way...
Please give idea about this. ? thx
What you want is possible and not that strange at all, you have two applications registered for push in the developer console with two projects ids and want each of your Android application to be able to receive notifications from both ?
If thats what you want its possible you just need to register to both sender ids in the android applications check.
https://developer.android.com/google/gcm/adv.html#multi-senders
basically:
...
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID_ONE, SENDER_ID_TWO);
....
push notification with 2 different apps are possible,i make it one database for both apps for save token id, generate 2 push notification. its working fine
I am trying to develop an android app that verifies a transaction initiated from a browser on a PC. I want the server application to push a notification of a new transaction to the app so the user can confirm to complete the transaction. The tricky bit is the transaction is specific to a particular person (I'm using this as an alternative to sending an SMS for example). Can anyone help on how to go about this? Is it possible to do this with C2DM or GCM?
Using Android GCM is advisable. The complete reference to GCM is available at
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
Step by step GCM development is given in there. It is really very helpful. Hope this is helpful to you.
The critical thing you need to keep in mind before making a decision is that when you are using GCM, you need to keep a track of the users by keeping their GCM_ID in your database. You can add a gcm_id column to your users table for this and whenever the user opens your app, the gcm_id should be updated in your database. The gcm_id of the user's phone can change, from the official docs:
Note that Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times
GCM push notifications wont be able to reach your users mobile phone all the time,especially if his phone is not connected to internet or switched off.You are using this for transactions etc, so I assume that the notifications must not fail. You should keep a check in your web application to send an SMS or notify the user that this has failed. You should get a response from GCM to your server through which you can identify a failed case.