Connecting Two iOS Devices via Node.js Server Backend - ios

I'm fairly new to swift and backend development, so please take it easy on me if my logic is flawed.
I'm trying to build an uber style app for ios and have a user side interface, a driver side interface, and a backend built in node.js. My question is how do I communicate when someone has chosen a "driver" from the user side to the driver side. I'm assuming it's a combination of a put request from the user side with get requests from the driver side, but I'm confused as to how to notify the driver side app when changes have occurred. Do I have to constantly be making get requests to the database or is there a better way to hold a connection between node and the app?
Any help is greatly appreciated.

Let me start out by saying that I don't have any personal experience with the technologies/frameworks I mention here (apart from Realm, but not for the purpose you're after), so, consider this a list of things you could look into.
Websockets
One way of doing this could be using websockets to hold the connection. If that is what you're after, then you could look at this tutorial about using websockets in an iOS app.
However...I can see some problems using straight websockets. For instance: what happens if your app is backgrounded and a message is sent to it? You won't get a notification as far as I can see.
Therefore you could also look into "pure native" frameworks to help you. By this I mean Realm or Firebase
Realm
Realm is a mobile database to use in your apps, compare it to Core Data for instance.
Some time last year however, Realm released something they call Realm Mobile Platform.
As it says on the tin:
Realm objects are always live, which means that they always have the latest data. Subscribe to notifications to get updates when data changes, then update your UI.
Maybe you could use that for your "driver side" app? Push a ride to the drivers database and it will magically be pushed to his/her device.
Firebase
Another contender is Firebase. They have something called Firebase Realtime Database which seems to do more or less the same as Realm Mobile Platform.
So...if it was me, I think I would look into one of those two products, but...I don't know if this collides with your current node.js setup.
Hope that helps to raise your confusion to a higher level at least :)

Related

Which backend service to use for iOS client, flask vs node.js vs firebase firestore?

This is not a coding query. Rather an starting point query.
I am new to iOS app development. I have been given a project by my university to make two iOS applications. One application will store few information about dustbin, like the dustbin's serial number, its type and its location in the campus. The location are named as zone A or B or C. These locations will contain their respective geographic information. These information will be sent to another iOS app. The second iOS app have the functionality of generating a map and routing the app user to the dustbin location. The map and routing facility is to be provided by HERE APIs (it is a constraint, and I cant be flexible with this). All this information flow will be facilitated by a server in between. Also, there should be a database storage management system.
Now note that, the server is not generating any active information itself. It is acting as a PASSIVE element. Client_1 is sending the message to Client_2, and this message is going through the server. this message is of course stored in a database.
Now I have few questions, or I should say few points that I dont understand and I am stuck at it.
Should I use Flask or node.js or Firebase firestore is sufficient?
If I do need to use firestore with flask or node.js, where shall I implement the firestore framework, on the server side (flask or node.js) or at the client side (iOS) ?
If I have to use the firestore in client side, do I need to implement it on both the client codes?
Given that I have to use firestore with one of the server, which one shall I use? Flask or node.js?
The above are few queries, which will help me get started on iOS app development. (Note that the iOS coding is being done with Swift 5.1)
Thank you all.
Firestore will work only as your database, where you could keep collections and documents, regarding the dustbins. As mentioned in the official Firestore documentation:
Use our flexible, scalable NoSQL cloud database to store and sync data for client- and server-side development.
So, you can actually develop your applications using it on either client or server sides. It would depend more on what you would prefer. Firestore supports Node.js, so, considering that, using Node.js makes more sense than Flask.
You can get a nice tutorial on how to do that, accessing the below article.
Write to cloud Firestore using node.js server
However, it's possible to use Firestore, as very well explained in this article, directly with Swift.
There isn't a "final" or correct answer for your question. For this reason, I would recommend you to take a look at both of them and make the decision based on your knowledge and preferences.
Let me know if the information helped you!

Swift - app that requires communication between phones on different networks

I'm just starting iOS app development with Swift (and in general) and I'm looking to get some information on popular practices when creating apps that require communication over arbitrary networks (i.e. not necessarily on the same network). I tried searching this on google but the answers weren't entirely what I was looking for; hopefully somebody can point be in the right direction. I wouldn't mind paying for a service, but unfortunately I don't know the first thing about backends and don't want to end up overpaying for services that I don't need. For example, I found an API called Parse, but I think it has far too many features that wouldn't benefit my app. Here's the main premise of the app:
There are two versions of the app - one for Admins and one for Employees
The Admins have the ability to post notes to a central list of notes for the employees to see
The Employees can access this list and scroll through it to pick which one they want to open. After a certain number of time, the notes expire and are removed from the list automatically
It's as simple as that. There likely won't be too many notes getting sent at once, so a large database isn't needed. My questions are as follows:
Do I need a database to store the notes, or can I handle it in some other way?
How is communication generally handled? The only things I've come across are ways to communicate when you're on the same WiFi or Bluetooth, but I haven't seen anything outside of that. How does an app like GroupMe communicate to users?
This is more of a general question, but how can you tell if you need a backend or not? I'm still kinda confused on the interaction between the frontend and backend.
Any help for any of the questions is greatly appreciated. I feel as though I don't even know where to start with a project like this.
EDIT: To clarify, I'm just looking for a place to start, not code or any implementation.
It's as simple as that. There likely won't be too many notes getting sent at once, so a large database isn't needed. My questions are as follows:
Do I need a database to store the notes, or can I handle it in some other way?
Yes you need some kind of database. That could be something complex like MySQL or something simple like writing a txt file for each note to the disk, with the filename being the date of the note.
You could use a service like Parse or run your own PHP server and write the software yourself. Parse is cheaper for a small database, running your own PHP server is cheaper for a big one and it gives you more control.
(You don't have to use PHP, but that is the most popular language for these things and it's what I use).
How is communication generally handled? The only things I've come across are ways to communicate when you're on the same WiFi or Bluetooth, but I haven't seen anything outside of that. How does an app like GroupMe communicate to users?
Usually your the phone sends a HTTP POST request to the server with some text in JSON format in the body of the HTTP request.
The server then responds with more text in JSON format in the response.
On the phone you use NSURLSession to handle to do the network communication and NSJSONSerialization to encode/decode the content. On the server, there will be something equivalent available.
Usually there would be a username and password or some other authentication system in the HTTP POST JSON text that tells the server wether or not the user is allowed to do whatever they're trying to do.
All communication between the phone and the server must be encrypted using SSL to protect your users. Do your homework and make sure you get this part right before you deploy your app to the store.
Parse will handle all of that stuff for you, but it's good to at least understand what's going on.
This is more of a general question, but how can you tell if you need a backend or not? I'm still kinda confused on the interaction between the frontend and backend.
You know you need a backend if you want two devices to communicate without being on the same WiFi/Bluetooth network. This is a security feature that cell network carriers (and home broadband ISPs) enforce to prevent malicious activity.
Generally only a commercial internet connection (and commercial router) will allow anonymous incoming network packets to get through to a phone/computer connected via that internet connection. Consumer internet connections only allow traffic coming in from a known source (for example, if you ask Google for some data, the router will temporarily allow Google to send some data to you. But if Google just sends some data without a phone/computer in your home asking for it, then it will be rejected).
You should be able to take what I've written and do a bunch of research.
If you decide to go with writing your own system in PHP, it comes pre-installed with OS X (just has to be enabled) and you can access it by IP address from the phone as long as you're on the same IP address. That should get you started for testing/development purposes at least.
The only part you won't have is SSL. Starting in iOS 9 (it's almost here!) you will need to disable NSURLSession's built in check for SSL or else it won't let you connect to the test server.

Apple swift - How can an app connect to existing heroku/S3 database

Im new to iOS and new to SWIFT with no previous experience with Obj-C. But, Im not new to Ruby. I have a web based app on heroku and am beginning to learn SWIFT so I can build an iOS counterpart. I need to wrap my head around the bigger picture before I can get started and I can not figure out how these apps connect to databases.
Can an iOS app connect to an S3 database...and share that database with a website? Is there documentation on this process that I have over looked.
Connecting an iOS app to a public database would really be a bad idea - all server logic should be implemented on the client, and you would also need to hardcode database user name and password in your app.
A better way is to create a server app exposing a set of REST APIs and being responsible of dealing with the database. This way you can better control at server side what the app client is able to do on the database.
If you have an order entry app, for instance, you can create APIs to:
login
register
create an order
modify an order
add a contact
delete a contact
etc...
Some of the advantages are that:
in case you need to update the logic (but not the API interface), you just need to update the server, whereas in your scenario you'd need to release a new version of the mobile app
you control and limit how client apps access to the data (preventing for instance a user to access another user's orders)
if you want to develop the same app in another platform (android, ...), you reuse the same APIs
To get started, I'd suggest you to read the AFNetworking tutorial on raywenderlch.com, focused on a ios networking library, but talking about JSON, REST, remote APIs etc.
Next you have to choose a server side technology - the most popular nowadays is node.js - to get started you can read other tutorials on the same website:
http://www.raywenderlich.com/61078/write-simple-node-jsmongodb-web-service-ios-app
http://www.raywenderlich.com/61264/write-ios-app-uses-node-jsmongodb-web-service
if you don't want to use node.js and/or mongodb... the same architecture applies, just languages and technologies differ. Just transpose what you learn from there.
If you want to read about other languages to use at server side, just google for it - if you want to use ruby, try with ios rest api server ruby.
Note: I made no mention of swift because your question looks more like an architectural problem than a language specific problem. The tutorials I mentioned here use objective-c, once you've designed an architecture and chosen the language at server side, you can start looking into how to call REST API from swift.

iOS app database and cloud storage

If I want to setup a database for an iOS app, and kind of make the app work in a sort of MVC style, is this possible through iOS alone, or do I need to create a web application to handle database interaction etc?
I would really like to be able to set up cloud storage/databasing directly from an iOS app. Is this possible? Does Apple have a platform for this, or do I need my own server?
In iOS the work with a web based services is very easy but on the other hand: need a "connection file".
it works like this:
the iphone has the info > sends it to a php/asp/asp.net/server side page, this page is taking (by "get" or "post") the info sent and than inserts it into the database, saves the file on the server and etc..
For reciving content from a web based service you also need a server side file to handle your trafic to the database, but now the output you get is in JSON.
you get back to the app an array (the file sends the array back) and than you use the array for handeling the conent you just got.
It may sound very hard but it is not as much as it seems. For your questions: there is not a way to connect directly through the app to a Cloud DataBase.
Now, when talking about owning a server and so: there are not so many companies which provide a cloud databse alone. but even if you get a cloud data base you can always host a domain somewhere cheap and the pages are only a few KB in weight any way...
And those files will be for connecting to the DataBase (The middle-men for the app).
That is a short explanation about connecting to web based services in iOS Developing.

how to synchronisation over multiple mobile devices

Is there anyone who worked out a synchronisation plan for a mobile application? I've been searching for it, but can't find a good example. I'm looking for a plan such as I think evernote uses to sync the files on the mobile phone with the backend.
My current plan:
- when you start the app: all your files will be downloaded from the backend using you username and password
- when you create a new object and there is network connection: object is stored localy in the core data (IOS), and transferred to the backend
- when you create a new object, but there is no network connection: the object is stored locally, and transferred when you are connected to the network and press sync.
All suggestions are welcome!
tahnks!
Sorry, I did forget some important information...
I'm using a grails backend
the frontend (mobile application) is an IOS app
Is there a good way to make sure there are nog file/version conflicts between the different devices?
You cold use various ways.
At my advice, the best one is to use the Parse framework. It is very easy to use and simple. Log in and save objet all in one. Please visit this: http://parse.com
Otherwise, You can use iCloud to store and synchronize your objects.
Find the Mobile Backend-as-a-Service (MBaaS) that fits your app best.
This link can get you started in your search.

Resources