Can Google App Engine be used for "check for updated" and download binary file web service? - iphone

I'm a Google App Engine newbie and would be grateful for any help. I have an iPhone app which sources data from an sqlite db stored localling on the device.
I'd like to set up a Google App Engine web service which my iPhone client will talk to and check if there is a newer version of the sqlite database it needs to download.
So iPhone client hits the web service with some kind of version number/timestamp and if there is a newer file, the App Engine will notify the client and the client will then request the new database to download which the App Engine will serve.
Is it possible to set up a web service in Google App Engine to do this? Could anyone point me to any sample code / tutorials please?
Many Thanks

What I would do is keep the SQLite DB as a gzipped blob in the datastore. Use the SHA1 hash as an etag. The client does a GET request with the etag header, and the server either responds with a 304 Not Modified or a 200 and the blob contents in the response body.
There is an API specifically for blobs, called the Blobstore API, but to use it you need to have billing enabled. Without billing enabled you can still easily serve blobs, but you'll be limited to 10MB per request, response, and entity size. If your zipped database is larger than that, you could conceivably break up the download into multiple requests, since you control both the client and server code. A custom blob handler that just uses the datastore might look like this:
class MyModel(db.Model):
body = db.BlobProperty()
class MyBlobHandler(webapp.RequestHandler):
def get(self):
entity_key = self.request.get("entity_key")
entity = MyModel.get(entity_key)
self.response.headers['Content-type'] = 'what/ever'
self.response.out.write(entity.body)
def put(self):
entity = MyModel(body=db.Blob(self.request.body))
entity.put()
self.response.out.write(entity.key())

This is entirely possible with App Engine, given that you're making HTTP requests.
The best code and tutorials, in my opinion, is the official Google App Engine docs. Everything you'll need is there.

Related

Angular PWA Offline Storage

I’m building a new web application which needs to work seamlessly even when there is no internet connection. I’ve selected Angular and am building a PWA as it comes with built-in functionality to make the application work offline. So far, I have the service worker working perfectly and driven by the manifest file, this very nicely caches the static content and I’ve set it to cache a bunch of API requests which I want to use whilst the application is offline.
In addition to this, I’ve used localStorage to store attempts to invoke put, post and delete API requests when the user is offline. Once the internet connection is re-established, the requests stored in localStorage are sent to the server.
This far in my proof of concept, the user can access content whilst offline, edit data and the data gets synced with the server once the user’s internet connection is re-established. This is where my quandary begins though. There is API request data cached automatically by the service worker as defined in the manifest file, and there is a separate store of data for data edits whilst offline. This leads to a situation where the user edits some data, saves the data, refreshes the page and the data is served by the service worker cached API.
Is there a built in mechanism to update API data cached automatically by the service worker? I don’t fancy trying to unpick this manually as it seems hacky and I can’t imagine it’ll be future proof as service workers evolve.
If there isn’t a standard way to achieve what I need to do, is it common for developers to take full control of offline data by storing it all in IndexedDB/localStorage manually? i.e. I could invoke API requests and write some code which caches the results in a structured format in IndexedDB to form an offline database, then writes back to the offline database whenever the user edits some data, and uploads any data edits when the user is back online. I don’t envisage any technical problems with doing this, it just seems like a lot of effort to achieve something which I was hoping to be standard functionality.
I’m fairly new to developing with Angular, but have many years of other development experience. So please forgive me if I’m asking obvious questions, I just can’t seem to find a good article on best practices for working with data storage with service workers.
Thanks
I have a project where my users can edit local data when they are offline and I use Cloud Firestore to have a local database cached available. If I understood you correctly, this would be exactly your requirement.
The benefit of this solution is that with just one line of code, you get not only a local db, but also all the changes made offline are automatically synchronised with the server once the client gets online again.
firebase.firestore().enablePersistence()
.catch(function(err) {
// log the error
});
// Subsequent queries will use persistence, if it was enabled successfully
If using this NoSQL database is an option for you I would go with it, otherwise you need to implement the local updates by yourself as there is not a built in solution for that.

handling iPhone app in offline/online modes

We are looking to develop an application that will get data from a web service if there is internet connectivity, and store this data using Core Data to Sqlite database just for viewing only (no updates will take place to local data), and whenever there is internet connectivity the app (or possibly a background thread) keeps checking the web service for new data.
How to know that the data which returned by the web service contains new records, and that the app should only store the new data, not the whole dataset again?
Is there a tutorial available on the web for a similar scenario?
My solution is to have an 'added' field in the database (Both local and remote) then when the service is called,the phone passes the most recent updated date/time in the local DB as a parameter...so the service only returns new data
Check out RestKit. It has hooks for reachability as well as hooks into Core Data.

how to access database without webservice?

I am developing an iphone application and need to access Oracle/SQL database that installed on a server, and I dont want to develop a web service to read/write data, is there any other way to access the database?
Connecting to a remote DB directly from an iPhone/iPad App is a very bad idea. Imagine someone with a jailbroken iPhone and a simple packet sniffer.... It would be incredibly easy to compromise the security of your Database.
The best way to acomplish this is to wrap it in php via a web server on your remote Database server. You can then run a query on the DB with a simple http POST request and have the page return xml/json/whatever.
You could look through CocoaMySQL-src for some other ideas though. I think the project is dead/no longer active, but the code might still be useful.

How to synch SQLite data to server in iPhone

I'm a total noob when it comes to iPhone development and have been tasked to create a database app that can download and upload sqlite data to and from a server via http using web services. So far I already have a form for retrieving and saving data to a SQLite database and now I need some information on how I can upload the SQLite data to a server. The SQLite database will only have one table with 3 columns and about 200 rows max. I hope somebody can point me to the right direction or lead me to some sample codes.
Appreciate any help.
As you are using HTTP to get data into the iPhone, you should also use HTTP to get data out of the iPhone. That way, you can query the SQLITE database and send the data through HTTP to a remote server.
It's pretty simple to accomplish since you have all the HTTP protocol implemented in the SDK.
On the server side, you can use whatever you want: Apache+PHP, Tomcat, JBoss, ASP.NET, you name it.

What's the best way to do one-way synching from a server-side database to iPhone?

I've got a database on my server which is about 3mb big. I'd like to ship that with my iphone application.
The most important thing is that I'd like to promote changes to the database (insert, updates, deletes) to the iphone. What's the best way of doing that? I mean - what is necessary on
- the server
- the client (= iphone)
- between; how to transfer this data?
I'm pretty free in using technologies serverside; right now, I've got an sqlite-database on the server filled with the data I'd like to sync to the iphones.
How often do you need the database to be updated, and how urgent are the changes?
If the database updates are infrequent and non-urgent, I'd have the app check for a new version of the database on startup, and if it has changed, download the entire new file.
The app would always download a small metadata file from a known URL on startup. The metadata file contains an version identifier for the latest version and a location where that version of the database can be downloaded. If the version identifier has changed from the version the app already has, will download the new version. If the version identifier has not changed, or if it can't check, the app can keep using the version it has.
Pro tip: if you want to show a progress bar for the download, include the size of the database in the metadata file. Cell networks often have transparent proxies that strip out the Content-Length header from HTTP responses.
Try using web hooks.
The concept of a WebHook is simple. A
WebHook is an HTTP callback: an HTTP
POST that occurs when something
happens; a simple event-notification
via HTTP POST.
A web application implementing
WebHooks will POST a message to a URL
when certain things happen. When a web
application enables users to register
their own URLs, the users can then
extend, customize, and integrate that
application with their own custom
extensions or even with other
applications around the web. For the
user, WebHooks are a way to receive
valuable information when it happens,
rather than continually polling for
that data and receiving nothing
valuable most of the time. WebHooks
have enormous potential and are
limited only by your imagination! (No,
it can't wash the dishes. Yet.)
You can find out more on Webhooks here:
http://www.webhooks.org/ and http://webhooks.pbworks.com/
Wonder if you have considered using a Sync Framework to manage the synchronization. If that interests you can take a look at the open source project, OpenMobster's Sync service. You can do the following sync operations
two-way
one-way client
one-way device
bootup
Besides that, all modifications are automatically tracked and synced with the Cloud. You can have your app offline when network connection is down. It will track any changes and automatically in the background synchronize it with the cloud when the connection returns. It also provides synchronization like iCloud across multiple devices
Also, modifications in the Cloud are synched using Push notifications, so the data is always current even if it is stored locally.
Here is a link to the open source project: http://openmobster.googlecode.com
Here is a link to iPhone App Sync: http://code.google.com/p/openmobster/wiki/iPhoneSyncApp