How do you store data remotely in an iOS app? - objective-c

I have an app that relies on some key value pairs where the value could change at a point in the future due to 3rd party api. The app is only useful when connected to the internet by the way. If any values change I don't want issue a new version of the app - I would rather that these values were pulled from a webservice/static xml file on my server. I would only need to pull these if I encountered an error.
Is there a standard way to do this or should I just roll my own?
EDIT: I'm not so interested in a server side technology - I think a flat file will suffice. What I'm interested in is what format should the flat file should be and how to cache it into my application once I get an error.

try redis, high-performance key-value store. used by some of the big cloud players, like cloudfoundry. Have a look at http://redis.io/. Objective-c client is available at http://redis.io/clients.

I figured out the best way for my use scenario:
I setup a json file on S3 which required authentication. I then used AWS for Objective C to authenticate so I could access that file.
I decided that I only needed to update the local info when the applicationDidBecomeActive in the App Delegate. I then got the json async and on success I then checked a version number in the json and if outdated wrote the changes to NSUSerDefaults (which are then used through the app.) If there was an error getting the json file I just continued as I would already have the previous set of NSUserDefaults that would do the job until the user next made the app active.
This solution worked best for me as it's simple to maintain and should easily handle the load even if my app were popular.

Have you considered using iCloud? It has support for key value pairs. More info here: http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/iCloud/iCloud.html

Related

Saving data on phone in a Cordova app

I am making a mobile app using Cordova and I need to save some sensitive and not so sensitive data inside the phone. I am a bit lost on what is the best way to do it.
I need to save:
A JSON web-token (for authentication).
A response from server (I save this to populate my page in case the GET request fails).
Coordinates information when user is logging data to the app (for later upload to a server from with in the app). These will be many separate logs, and can be large in size for local storage ~5-10 MB.
Till now i have been successfully saving everything I need to the local storage but I don't think that is the correct way to do it. So that is why I need some help in deciding what is the best course to take from security point of view.
Saving server response is just for better UI experience and static in size so I guess local storage is a good option to use.
But web-tokens and GPS logs is sensitive information and I dont want to keep it in the local storage as it is accessible from outside the app.
What other options do I have?
Cordova still doesn't have encrypted storage.
Is saving to files a good approach? This here says that data contained inside cordova.file.applicationStorageDirectory is private to the app.So can I use it to save the logs and the token?
The plugin also lists the file systems for Android and iOS and lists which of those are private.
I am currently working with android phones but want to extend the app to iOS later. I have never worked with file systems and caches before so I am a bit lost.

How does the Dropbox Datastore API differ from Parse?

How does the Dropbox Datastore API differ from similar offerings like Parse? One difference that I see is that my users pay for server storage instead of me. Are there other differences?
Disclaimer: I'm a Dropbox engineer who worked on the Datastore API, and know about the Parse API only indirectly. Weigh my opinion appropriately. Major differences I know of (pro and con):
Dropbox Datastores are free to the developer, and free the user for the first 5MB per-app (after which their Dropbox quota applies). Parse charges developers based on how many API requests they’re making.
Parse has minimal offline support, while Dropbox has full offline operation. With Dropbox, if the developer modifies data while offline, those modifications will be reflected in subsequent queries (with Parse, those changes are not reflected). Dropbox provides on-device query logic (unlike Parse) so that apps can continue to generate the views they need to, even when there’s no Internet available. In addition, Parse does not provide conflict resolution or querying offline.
Parse provides the ability to share data between users, and global data for all users of the app. Dropbox Datastores only support per-user data (for each app) for now (sharing is on the roadmap).
I would also add that:
Parse is full feature of backend of as service. You can find a pretty complete list of the other player in this field: http://en.wikipedia.org/wiki/Backend_as_a_service. They provide feature like:
Data service
User registration/auth
Push notification
Social
The dropbox Datastore APIs is more focusing on data services. (You also got the User part for free too?) Also it works full offline.
The Parse framework can store data that can be ready by any user in the application.
The Dropbox datastore, store data for each user, and you can't accesss data from other user. That's the main difference.
So easy to get lost in this since you have to read between the lines. My take is that with Datastore you are working with objects stored offline locally as json. I'm hoping they will soon release a Xamarin Android component - they released an IOS component last month. Since Xamarin targets both Android and IOS and Winphone, who knows why they made a dedicated IOS DLL for Xamarin but I digress. With Parse, it appears to me their intent is the always-connected-device. Sure you can save queries locally and you can save (save eventually) locally where Parse will push to the server when it is connected. But saving "eventually" and saving queries for offline work is a different design than just saving and letting Parse do it all in the background for you - which it does not unless I have missed something that would make this attractive to me. I cannot see Parse useable for devices that you know will be sometimes-connected, without a lot of code to make this happen and sync.

Basic iOS Networking Questions

I am trying to do my first App which is a basic joke app that uses tableViews and allows users to add their own jokes to the app database. My problem is in the networking department and I think I'm getting confused with all that is out there. I have a couple basic questions that I was hoping to get answers or opinions on:
I am really confused about the path that is taken from the app on the iphone to the database that is holding the data. Does the tableview controller call a AFNetworking object, that then sends a JSON object to a server-side script(??), that then queries a SQL database and returns the data? I am just looking for a basic path that allows the user to add their own joke to the database.
Is this a URL request? When I see URL request I think of a web page.
I have a website that is hosted on GoDaddy.com. Is this also sufficient to hold the database for the jokes on the iOS app?
I have been searching for days and have gotten no simple answer. I just want to study the correct subjects instead of wasting time. ANY help or pointers would be appreciated.
You have two forms of storage here - some form of web store (such as a server database technology like MySQL) and the local iOS CoreData (if you want to store locally, or make a new request every time thus requiring a connection). You can use web requests (perhaps using the AFNetworking library) to ensure that the local store and the online store match. A typical flow could be for example - on app launch perform a GET request to pull all jokes from the server using a service URL that returns a JSON file, then update Coredata. To upload a new joke, use a POST request which performs a similar function.
A 'URL request' maps to a web technology which uses some form of logic to determine how to return some data. For example, the request may arrive at a web server (such as Apache) which routes your request to a PHP controller file which then talks with the database and returns your data.
GoDaddy is a hosting platform that supports PHP and MySQL (amongst other technologies that will do the same trick), so yes.
In your situation, I would study the Model-View-Controller design pattern. Your app will be a great learning experience I think, you should pick up a lot of core concepts.
EDIT to answer your question in the first comment:
Your question:
1. Are JSON files stored on the device or the server? 2. Does JSON replace JavaScript?
Answers:
JSON is short for JavaScript Object Notation, it's just a way of representing data and doesn't replace anything. It's particularly useful because most languages support parsing JSON in a way that the technology understands. It's a handy way of sending data around because it's pretty lightweight and is widely supported.
In a case like this, the JSON would probably not be stored on the server. The data would be stored in a database. Your request will be mapped to a server side technology such as PHP or Ruby which will then ask the database for the information, convert it to JSON for sending and return it to the client. (It is possible to store data on a server in a JSON file, but you would have to write your server side code to manipulate the JSON file directly, it would be hard work and way less elegant!)
The client (in this case an iOS device) will parse the JSON into an object that Objective-C can play with, like an NSDictionary.
Hope that helps!

Time limited Shareware

I'm thinking about making a time limited full version of my App, so users can try it for example 7 days.
Is there a recommended Obj-C library?
First of all do not store your data inside the app. Otherwise it would be simple to delete the App from the filesystem and download it again restarting the countdown. Store it in User preferences or Application Support instead. You could use a plist for this. You could also use a hidden file if you like. Just don't make it too complicated or too invasive. Your app can be cracked no matter what security measures you use in the end. Just be fair enough to the end user that could be a prospective customer.
Here is a very nice link on the topic of implementing a time-limited trial in Cocoa:
http://lipidity.com/apple/shareware-licensing-techniques/
Without possibility to protect your data from manipulation/deletion it is not possible to do.
How do yo check, if it is first start of your application, if all your data is wiped out.
Some alternative is "hardcoded" id token and connection to the rest of world (at least for first start, to grab any kind signed data key)
Maybe you could use a server where store UUID's and first time they launched the App. Then, Each time they open your application, it asks your server if they can use it or not. It's harder than store dates on device but if you do that, users will access your application simply changing the date of the device on Settings.

Android MySQL php+JSON alternative

I have written a simple database driven app in C# which uses a 2 table MySQL database. This is all a learning curve for me (except c#, which I am now comfortable with)
The app is small, has a couple of datagridviews, uses a few sql select/inserts statments to populate the datagridviews and also update records.
I want to port this app to Android. All of the internet sources I can find recommend a middle php sript which accepts http requests in order to fetch the data from MySQL and then return the results back to the android device where it is parsed with JSON etc etc.
This method is a little out of my reach since I dont have php experience, all of my attempts to implement the php layer have failed, speciially the android app was not receiving any data back, I'm assuming I messed up somewhere inside the php file.
Is there an easier (more noobproof) way to interact with the MySQL database from within android which doesnt require the need for php + JSON? Any ideas are appreciated, thank you in advance.
If you are comfortable with C#, why not use ASP.Net MVC for the middle man?
MVC is especially easy to deal with JSON, and you actually only need to create those "controllers" (as models should already be there from your existing app, and JSON don't need the View to display).
You can create a Web Service with C# that handles the data retrieval from the database; no need to go with PHP. Try create one with WCF API (check this question in order to create one). In order to create an Android client that consumes JSON on Android check this link.
If your mobile application have to access a database over the network you should indeed build a web service fronted to the database.
By putting a web access layer on top of the database you can expose the required queries in an abstracted, secure and convenient manner.
Though this sort of web service architecture can be implemented with PHP + JSON other technologies can be used as well. If you feel more comfortable with C# you can use it to build the web service instead. By doing so you may even be able to reuse some of the code from your existing application.
Actually, it would be better to take php in middle of android & mysql, due to the security concern and by the way this is the most easiest & comfortable method. here is link link. I hope you like it.