Calling Meteor from Native iOS Application - ios

We are building an application that consists of a web app and a native iOS client. The web app is pretty straight forward with Meteor. But on the Native iOS App was wondering if someone can give us some pointers on the best practices for that app to call into meteor. I have seen that there is something like the collectionsapi api which exposes meteor collections over http, but am not sure how we would handle authentication for Native iOS clients if we used something like the collectionsapi or similar. Any pointers from some folks who have done this would be greatly appreciated.

Meteor's communication system is based on DDP (Distributed Data Protocol). You can access meteor's methods & make subscriptions to data which is probably the best way to go since you can get live data back too!
There is an objective-c client but its not been maintained : https://github.com/alansikora/objective-c_ddp-client
The ddp client was originally made prior to an official ddp specification (pre1). So you would have to adjust the client a bit to bring it up to date. Luckily its not too much work. The full DDP spec can be found here: https://github.com/meteor/meteor/blob/master/packages/livedata/DDP.md
Using DDP is a very attractive alternative to making a traditional REST request (POST,GET,PUT,etc). As the data on the wire is the same system meteor's client communicates to its server. So if you're able to make something on meteor work in a web browser you could pretty much replicate it on a native iOS client.

If you are still wondering about this, I've been working on a free, open source project that enables native ios clients to do meteor auth (SRP auth) and communicate via DDP. The project lives here: https://github.com/boundsj/ObjectiveDDP
There is an example app here: https://github.com/boundsj/ObjectiveDDP/tree/master/Example

Related

NodeJS as an instant messaging server for a MVP chat service

I am working on a chat service with some unique features in it, and thinking about a server to dispatch messages and do all the IM-related stuff. First-priority client is going to be for iOS, built with Swift.
Is it feasible to create server, based on NodeJS Express, or may be Loopback? I have had a look at multiple choices, including ready solutions, like QuickBlox, Parse.
As for creating it from scratch, I think about NodeJS or Erlang.
At what stage should I make a decision so that not to waste too much time on reconfiguring everything for scaling and rapidity and convenience of development?
With technologies like Socket.io, Node.js, and Express, you could make a chat application fairly quickly.
Sockets are typically the best solution and the most common route to implementing a chat system, as they provide two way communication between the client and the server.
You could use practically any backend for a socket server, but it may end up being quicker to use Node.js and socket.io depending on your comfortability level with JavaScript.
All you would need is a socket compatible server and a client side library that connects to a socket server - there are plenty of JavaScript libs out there, including a socket.io-client.
Check out socket.io's chat demo on their site for a quick look at how it works:
http://socket.io/demos/chat/
They even provide a first party iOS Swift client:
https://github.com/socketio/socket.io-client-swift
Personally I recommend you to checkout SailsJS, a great framework for building API & chat server at the same time. It adopts socket.io internally so every route in a Sails app is compatible with socket.io (in other words, you can decide to call an API request via Socket anytime you wish!)
I've built a complete, working iOS App having chat feature. Its backend was completely developed using SailsJS. It saved me hundreds of hours. Sails documentation also mentions about scaling for production. Please have a look at http://sailsjs.org

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 native app talking to an API or direct database connections?

Folks,
Designing an ios application, and would like to confirm my strategy. There is a database (dynamo/mongo/etc) i am building up, which the app needs to make use of. Is it smart to front the database with an API, and have the ios app authenticate against the api.
This way the app makes calls to the api instead of directly to the database?
Would you suggest node.js be a good place to start crafting the web api with?
Thanks!
Yes, access the data via an API. Whether fancy authentication is needed, depends on what is stored in your database, and what your application is designed to do. Here is one resource (among millions) on API design: http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api
Also, here is a popular networking library for iOS: https://github.com/AFNetworking/AFNetworking
As for what technology to use, that too open ended and you will get 10 answers for every technology available. This should help though: https://softwareengineering.stackexchange.com/q/154519/44948

PhoneGap with Django Backend

I'm working on a web application that uses django.
I would like to create a native application of the site for ios / android using phone gap.
Is this possible? As I understand native devices cannot interpret python code.
It is early in the project and if it proves too difficult I may go with a different framework I.e backbone.js.
Any thoughts / experiences?
That's right, you cannot run python code on iOS or Android using PhoneGap, but there is no need to do that. Yes, you can build a native mobile application of your site using PhoneGap.
I'll try to explain a bit how these technologies compare to each other:
Django is a python web framework running on a web server
PhoneGap is a framework for building native mobile applications using web technologies (HTML5+CSS+Javascript), the application will run on a mobile device
One common approach is to build the mobile UI with i.e. jQuery Mobile and use the Django web application to provide a RESTful API to get data to the application.
Take a look at this another question for more details.
Edit: Answer the question in the first comment
Yes, it's possible to build a fast and well working application with these frameworks. The performance with today's smartphones is more dependent on the quality of the implementation than i.e. jQuery mobile and Django in themselves.
Basically with PhoneGap there are three different ways for showing the content to the user:
server side generated pages
pages generated on the client side with Javascript usin data from the server, transferred in a predefined format using for example JSON
a combination of the previous two
This answer clarifies server-client communication and page rendering quite well.
You could use PhoneGap a bit like a constrained web browser, and basically show content directly from your server as you would when the user accesses the site with a normal web browser. But I don't recommend this, though. This approach has many downsides to it (i.e. what happens when the user opens a link from your website leading to another website?)
To be accurate, at least in my opinion, UI written with Javascript and running inside an app built with PhoneGap is not native. Comparing native applications and PhoneGap applications is another thing, here is one take on explaining the differences.
I don't know what kind of service you are building, but in general I'd suggest evaluating the different approaches before starting to build an application. Would a responsive mobile optimized web site do or is there real need for what an app can provide?
If you decide to build an app with PhoneGap, I'd suggest that you do it with client side Javascript and fetch the data from the Django backend with XHR requests in JSON format. There are lots of examples available in the internet.

Can a native iOS client connect to a meteor.js server?

I'm really intrigued by the meteor.js framework. However, I'm not certain whether or not I can take advantage of the framework's real-time capabilities via the objective-C's native objects such as NSURLConnection. I have some specific questions referencing this question on how meteorjs works: How does the Meteor JavaScript framework work?
Let's start with web sockets:
The client/server messaging is done via websockets using something
like socks.js or socket.io.
Is there an objective-C library or framework for utilizing websockets in native apps that would be able to communicate with a Meteor server?
Second, is the mongoDB client:
The client side connection to mongodb is really cool. It replicates
the mongo-server driver into the client. Unfortunately, last I
checked, they were still working on securing this database connection.
This seems like the most intriguing part of meteor. However, does this mean there is no standard way to communicate to the meteor server other than executing strings of javascript in a hidden UIWebView?
For anyone interested in this, I've been working on an objective ddp client library here. I've only just started and there is no documentation yet, but everything works well. The project is here: https://github.com/boundsj/ObjectiveDDP
The specs for the ddp client are here: https://github.com/boundsj/ObjectiveDDP/blob/master/Specs/ObjectiveDDPSpec.mm
I'm also building a library for meteor auth so ios clients can authenticate with a meteor server using the password package. It's all put together and working in this sample todo app (also part of the same repo): https://github.com/boundsj/ObjectiveDDP/tree/master/Example
not a full answers but hopefully a few pointers to get you started.
Meteor uses a protocol called DDP - Distributed Data Protocol. The blog post introducing it is here: http://meteor.com/blog/2012/03/21/introducing-ddp
There is an Objective-C client library on github here: https://github.com/alansikora/objective-c_ddp-client Although I can't vouch for it and it has no real documentation, the code is short and should be reasonably understandable by someone who already writes Objective-C.
Other than that I would suggest digging in and see if you can uncover any techniques for iOS clients. It's early days for Meteor and were all learning how to use it.

Resources