Can I get response for POST method (Restful)? - ruby-on-rails

I want to make some request from iPhone app to my web service (Rails) and when is data procesed to get response with some string for example.
I read a lot about Apple's push notifications, but I need answer immediately and push notification can late.
I made POST request to my Rails app from my iPhone app, and it works.
First question(I got answer): But, can I get some string as response from Web service (Rails app)?
Second question: When I got request from iPhone app, how to notifies some iPad device for example (with running app) quickly from my Rails web app? One solution is push notification, is there something faster and safer?

If you just want a text string you could do render :text => 'Some string'. If you want/need a more structured response then you should respond with JSON or XML.

Related

Displaying notifications on iOS device handled by a Ruby on Rails web application

I'm building an iOS app that needs to have notifications display every time any user of that app does something like send another user a message. What I have currently is a working Ruby on Rails and Android app. The Rails app notifies Firebase when a notifiable activity occurs like so:
if active_time.save
fcm = FCM.new("AIzaSyDhMXi3797t2oZMxOTo-Nph8IoypRL8Ooc")
registration_ids = Array.new
for user in group.users do
if not user.token.nil?
registration_ids.push(user.token)
end
end
options = {data: {score: "123"}, notification: {body:"Active time added to " + group.name, title: "Groupsync"}}
response = fcm.send(registration_ids, options)
active_time.delay(run_at: active_time.start.getutc).send_group_live_notification
What I'm unsure about is how to get my iOS client to notice these activities and display notifications like its Android counterpart. I have set up FCM on the iOS client and am able to send notifications, just not sure what the next step is in terms of making the link.
EDIT: I should mention for the above piece of is controlled by my iOS client through HTTP POST requests
I recommend you using a service line OneSignal. It's free and you can set a lot of platforms there, between android, ios and web browsers. For ios you're gonna need a push certificate from apple (see more here: https://medium.com/#ankushaggarwal/generate-apns-certificate-for-ios-push-notifications-85e4a917d522). Once you set your configs for android and ios, for example, you can use their api and send the notifications using their ruby gem, for example (https://github.com/tbalthazar/onesignal-ruby).
Good luck!

Send push-notification every time website is updated

I want to make an application that sends out a push-notification every time a website is updated with new content. This website is updated 1-3 times every day. And it's contains a chronological feed, where each post had a datetime, video/image, title.
And I want the notification to contain this information, and link to the website(maybe via the app).
Now what method should I use to get this app going? How should I start, and proceed?
From your question's description, What I understood is this that you need to update your application whenever your website has new content.
This can be easily achieve using Remote/Push notification.
You can use Boolean type or String type which can be understand by app and web.
For example:
{
"aps": {
"alert": "Hello World",
"sound": "default"
"Content": {
"isNewContent": "1",
}
}
}
This is typical Custom notification object, you can send more details in that.
Here you see that in Content there is a parameter isNewCotent which has a value 1, this indicates that you have new content on web.
So now you can get call webservice to get new content from web server.
And If you dont know that how to implement Push Notification in iOS, you can check below tutorial, explained in detail.
Setting Up Push Notifications on iOS

When to authenticate to server in iOS app

I have an iOS app that authenticates to a remote API. The server gives back a token that is used for all the next requests. The authentication call is a simple POST to /api/auth.
My question is: where should I make this call in the app ?
I don't know if I should use it in the AppDelegete (willEnterForeground or didBecomeActive), because it may slow down the app launch. Moreover, this is asynchronous and if I try to make other requests in some controllers while the token hasn't returned, there will be errors.
So I thought about doing it in the root controller, but in the case the app was in the background for a long time and comes to foreground in another controller it doesn't work...
The last option would be to watch errors on every call, and re-authenticate when the server responds with a 'token expired' error. In that case I should probably have a special class for HTTP requests and error handling ?
I don't know what option is the best...

what idea should i use for this application iOS -json and local notification

hello all I'm asking if any one can help me what i should use for this idea
I'm developing iPhone 5 application this application for movies it's like reminder
i create php script can accept post request from iPhone and save the data in mysql ,
also there is another page on the script for display user movies .
i want my application every 1 minutes call the newMovies.php page and check return data( json)
if json key"New":"true"
the application will send local notification .
all this task on the background pls i need advice for this application .
if any one looking for same question , i will answer
finally i used , Timer on applicationDidEnterBackground
this timer will call selector (method)
and the selector will check if there is any things new and pus local notification .

How does an iOS device identify itself to server without user log in

I am writing an iOS app with a Rails API backend. The Rails backend will serve JSON data to the app. I have the following requirements.
The app will be a free download
The app will show data on a map
The app will show data in the vicinity of the user
Upon loading the app the device should send some unique identifier to the server identifying itself as a device that is running this app.
There will be no authentication for the user as it is not required. The data is available to anyone who downloads the app. All the server needs to know is that the client is a device running the app. The server cannot serve data to any other client
I would like to run the data using SSL between the device and server
The user location will be sent to the server and the server returns the corresponding pieces of data that are in the vicinity of the user
The client receives the JSON and caches the data locally.
Question: Given these requirements, how to set up steps 4 & 5?
Also: If I want to search more on this topic what keywords should I be googling for?
Consider using OpenUDID or SecureUDID.
I give you 2 options.
First of all, the easy way. From some time, apple forbids access to the device ID. However, they give you a device token instead.
To get this unique token, the user must register for remote notification.
Upon application launching, call the following function:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Then this callback will be called:
- (void)application:didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken.
Send the token to your server and you're done. Problems with this approach are obvious. Your user will have to register for remote notification.
Another approach is to use the MAC address of the wi-fi board.
To do this:
IPAddress.h
IPAddress.c
Import this files into your project.
Then use this function:
InitAddresses();
GetHWAddresses();
for (int i=0; i<MAXADDRS; ++i)
{
//There is a way you can obtain more info about the hw_addrs, but in general, it's the first.
NSLog(#"MAC: %s", hw_addrs[i]);
}
FreeAddresses();
Create a hash using the mac address above and you're done.
Hope it helps.
Upon first launch, the app sends a request to the server saying Hi, I'm a new client, give me an id! The server generates a new, random id and sends it back. The app saves the id locally and uses it henceforth to uniquely identify itself.

Resources