Get data from a server with Objective-C - php

I'm trying to make a notification system between a PHP server and an iOS device, just like in the Facebook App.
I already know how to make a PHP request via GET or POST and wait for a response. But I would like to receive server's responses without any request, is it possible? Or should I make a request every x seconds?

Look into Apple Push Notification Service (APNS). You send a message to the APNS server, and the server sends a notification to the device(s) you specified. This is standard practice for apps like Facebook.
When the device receives a notification, it sends it to the app (if the app is running) or alerts the user (if it's not). The user can choose to start the app, at which point the notification is delivered. The app can then respond by contacting your server to update its information or whatever.

Related

Getting "InvalidTokenFormat, Error 400" from Firebase Cloud Messaging

I am using Firebase Cloud Messaging for my android development with PHP as server side language. Right now, i'm able to :
Receive push notification sending using Firebase Console either both real apps and emulator.
Got it working when testing it out from terminal(curl)
So then, i tried sending from apps server(using php curl) instead of Firebase Console. And right now, encountered this weird message InvalidTokenFormat, Error 400 every time i'm request the POST request. Any thought?
Here is the link for Firebase Api were made : FirebaseApi Class
Feel free to ask for any inputs from meif above use case didn't clear enough. Thanks.
My mistake. The url should be(without slash at the end) :
https://fcm.googleapis.com/fcm/send
you need to send request to the firebase from your server with message of the notification and the token of the users then firebase will accept the request and broadcast the message to all the users (tokens that we provide) in form of a notification .
Firebase and device works on poll model, hence only firebase can send notification on your device , you can setup your poll with the device but google does not allow that because if each and every app starts to make a poll tunnel with the device , it will take up whole lot of resources.
Can you Post the raw request curl sends to the server? Normally curl does provide a printout for that, not sure about the php version.
CURLOPT_POSTFIELDS does not want a JSON. if you want to send a application/x-www-form-urlencoded request, use http_build_query($message) , or if you want to send a multipart/form-data request, give it the $message array directly.

How to get messege from server with less data usage in Android?

I am writing a Android program that get message from server. I can refresh my program every second to get message from server, but I don't want to do this work.
Is it possible to send message from server to client IP and then get message with my Android program (that installed in client device)?.
If it is not possible, please say me way to get message from server.
You can use this
1) Use push Notification in your app
2) When user click notification refresh your app (make a http request to your server fetch the update info).
OR
If you don't want to show notification in mobile which is no harm (almost every news app does this). Just don't create notification refresh you app.
for more information refer this
GCM
pushnotification in android

send notification to android device from server without GCM(Google Cloud Messaging)

I have to send notification from server to android device. I developed application which got notification from server by using GCM (Google Cloud Messaging). But as I already have server then why to use GCM. I am not getting the purpose of using GCM. Can we send notification from server to android application without using GCM.
General Communication Pattern :
Device --> HTTPRequest -- >Server , Server -->HTTPResponse --> Device
But in this case, the device gets a response only when you send a request from your device to the server. Hence, whenever you need something new from your server you need to make a
request.
Using GCM, you do not need to make this request explicitly to your server. You'll automatically be notified when something new happens (depending on your implementation).
You are having server but GCM is totally different thing then your server.
GCM will monitor Your Application server that any changes made or not ??
And if anything created then it will send you notification without refresh or reload the Application.
and GCM will send you notification when your application is not working as well

automatic sending notification to ios/ android devices using urban airship and php

I need to send push notifications to my app from my server and i am thinking to use urban airship and i am using PHP at back end. As much i got from urban's documentation ,my server need to send message to urban's server and urban's server will forward it to devices
Now ,i want to automate the process of sending of message from my server to urban's server. Actually, at my server, i am executing a script that go through database and fetch list of users to whom message need to send. so please guide me regarding automating sending process.
Yeah, you can use UrbanAirship (UA) for that. They provide a REST API (http://docs.urbanairship.com/connect/index.html) you can use to send to your audience (UA slang for your users).
So you basically just have to
use UA SDK in your apps. Basically, they will take off when you start your app, register with Google / Apple for push notifications and give you back a token that you have to store in your database
Handle any event where you want to send push notifications in your script
get call the data for the users from your database, i.e. the device type (android / ios / windows phone) and the token you received from UA for that user
send the data to UA in the way they want it (http://docs.urbanairship.com/connect/connect_send.html) and your good to go
If you want to run your script periodically I would propose just using a CronJob (https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job) that runs every X minutes / hours / days

C2DM and PHP Server

I'm trying to write the server side of my android app that uses C2DM. I'm going to write it in php. I basically am just doing tests right now. I copied the chrome to phone example for the actual android app and modified it to my liking. Right now my biggest question is the registration.
Let me get everything straightened out.
When registering the device for the first time, the app talks directly to my server. The server grabs the deviceid and responds back with a 200. Right?
So, on the php side of things, I grab the device id like $deviceid = $_POST['deviceId'] Right?
add it to my database. then respond back to the app.. How exactly do I send a particular response back? I assume in the header? I'm unsure how to do that.
Please confirm or deny that I'm on the right track and clear up any confusion.
Thanks for the help.
You don't respond back to the app. You must register your server with google's servers to get a server authentication token. You then use that server token and the device token in a post request to google's C2DM service to have google's servers send a push notification to the phone. Your app and your server never directly communicate when a push notification is sent in C2DM, it is all done through google, yet you need to implement a mechanism for your server to know the device id of the device it wants to send a message to.
This is a pretty detailed guide, though the server code is in Java:
www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
Make sure you have really gotten the IDs before sending to the server. If you are using an emulator for testing, you could do an echo over at the php script so the message will appear in your logcat.
Google refreshes expired registration IDs so your application should be able to pick up new notifications/ids from google and handle the message by sending to the database.

Categories