I am working on a custom framework which will be used by developers. I am saving some data locally inside my framework for that I am thinking to use UserDefaults but I want to know:
Is it the best method to do so?
If the app UserDefaults are cleared then will it clear my frameworks data also?
I want to know how can I store local data in ios framework. What is the best solution for this?
I am confused about it can anyone help?
It depends on the data you want to store.
If your goal is to keep some settings for your framework (e.g. whether some features should be enabled or not) then UserDefaults will do.
If you want to store user's data (or anything you can get from the server) then you should probably consider using CoreData, which is a native iOS/macOS/tvOS persistent storage.
You can also use Realm database, but it's not a good idea to use it in frameworks, since it will be added to any application which will use your framework (and the developers probably won't be happy about this).
Regarding you questions:
It depends, see above
Yes
Userdefaults is great but at times it turns into a mess if you have alot of information that needs to be stored. Specially the fact that you would need to manage a key/value relationship throughout the app and usually the keys end up being more than 10 plus ..
Just a suggestion but why not use CoreData to manage models and store data in sqlite db on device. When the framework is loaded you can check if the data exists if not then fetch it.
I would suggest using the functionality provided by apple natively rather than going for 3rd party solutions like Realm, with 3rd party you would need to upgrade to their latest version in order to make things work fine.
Please read these to clear any confusion.
https://cocoacasts.com/what-is-the-difference-between-core-data-and-sqlite/
Tutorial on using Coredata:
https://www.raywenderlich.com/7569-getting-started-with-core-data-tutorial
Related
I'd like to build a simple iOS only app that's going to be social. I don't yet have a way to monetize this app, so I'd like to keep this project as cheap as possible. Since it's iOS only, I figured I would use CloudKit because of its very generous free tier. However, if I ever decided to make this a cross platform app, would I be able to migrate my user data somewhere else?
I think you can use CloudKit with Android because of the CloudKit JS implementation. The real problem is, that I think that also the android user needs an iCloud Account do something with that.
So maybe the better way is to use google firebase.
https://firebase.google.com
As of December 2019, there is no simple way to migrate data from CloudKit. The data stored in each user's private data base is not accessible by the developer.
There is always the option to do this inside of the app for each individual user. If the data is not too large and complicated it should be easily done.
But make sure to inform the user and give them a choice to move or don't move the data. Let both services run for some time parallel before removing the cloudkit option for old users completely. Obviously moving data using the app can cause certain issues if the move doesn't go as planned.
I just wanted to do a quick sanity check with StackOverflow to confirm my suspicion. I'm creating an app and was tempted to use FMDB in Swift to store some data.I am treating this data as public in the sense that I assume it can be tampered with (and thus untrusted). This is because, after all, unlike a web app, this app runs on a user's device and thus they can access the .sql file and alter the database.
If I wanted to store information like if a user purchased something, unlocked certain weapons, or other data that I do not want to be altered in any way, I should not use a local database on the user's device.
Would you say this is correct and safe to proceed under this assumption? If I was looking to use the database to persist something important that took place, what would be a good approach? encryption with the key in the app, or maybe a hash or something?
If you want to secure your database, FMDB includes hooks for SQLCipher, which you have to obtain separately. See the various FMDB Encryption Methods that you can use once you have SQLCipher included in your project.
I would like to sync a core data app with a user with a different iCloud ID and I am trying to figure out the most graceful way to do this. I do not want the data to sync with all users, but want to be able to sync among family members for instance. From the research I have done, I do not think I can do that using iCloud Core Data sync because it only syncs between devices with the same iCloud ID. I have looked at this stackoverflow answer and read a little bit about Ensembles, Parcelkit and TICoreDataSync, Parse etc., but it is not clear to me if any of those options will allow me to sync with multiple users. Does anyone have a good method for syncing a Core Data app with multiple users?
Ensembles and TiCoreDataSync might work. They can use Dropbox file syncing, so in principle they should work with Dropbox shared folders. I don't think these are the main intended uses, so I suggest contacting the developers and/or doing some good testing yourself before assuming this would actually work.
You'll need to think about the user experience, though. At a minimum, your users would both need Dropbox accounts and would have to set up a shared folder before beginning to sync data this way.
Parcelkit probably won't work. It uses Dropbox's data store API which, unlike other Dropbox services, doesn't appear to support shared data.
Services that do support this kind of sharing exist-- for example, Parse and Firebase-- but make sure to review their pricing carefully before using them. Also of course, there have been any number of projects that have their own custom server back end, but that obviously requires having someone on the team who can do that kind of work.
You need to think about other device types (Android at least) if you want your application to be reaching more users.
I'm doing the same now by the following way:
Setup an online database with proper web services (careful with implementation for security matters - DB should NEVER be exposed by anything other than the web services).
Create a Class for your communication with the server (using Class methods with security handling like authentication and authorisation).
Use the class in your app to communicate with the server (SQL operations are done on the server).
To integrate with CoreData you need to create the model in your app similar to the structure in the backend database. Then you need to create a similar class for the app that deals with only local CoreData.
A higher level class might be required if you want to make sure that operations done on both server and local data storage.
Besides, you have to implement a lot of conditions to make sure that data written in local ONLY after making sure that it is stored online (or create an engine for differed operations to run later).
Another Way if you are familiar with notifications:
Use structured notifications between devices for data operations in order to keep everything in sync with other users. The problem with this is the "Autonomy" of the operations. If two operations were done in approximately the same time, you have to find a way to make sure the order of the operations is done properly (maybe timestamp or something).
I'm looking into the same thing for my app and I 'think' you can do a fairly unsecured version of what you are after using using the public folder in cloud kit as mentioned in this question (no accepted answer at time of posting) : Private data sharing using CloudKit
You would need to find a way to differentiate between data that is truly public and those shared among the users you need and some level of authentication.
I'm going to try exporting a permission file with access permission in it to whomever I want to share with combined with a unique identifier located in that permission file.
Keep in mind, as mentioned in the comments of the linked answer, my implementation will be security by obscurity (thanks for that phrase) unless you find a way of adding proper validation to it but my data is relatively insensitive.
Hope this, or any ridicule in the comments, points you in the right direction : )
When using PhoneGap, do users lose all of their saved data when they update an iOS app downloaded from iTunes?
I am hoping that anything stored in either Webstorage feature in Construct 2 will be preserved whenever someone downloads a new version of the app from iTunes, but I'm afraid to build a whole Apps only to have a bunch of upset users when they update the app. I know when I build an app in Objective C I have to go through some hoops to get the Core Data store to migrate correctly.
The other option is to mirror the data to an external server/database, but I want to avoid that expense and complication if I can.
If you change anything in the tables in CoreData then you would have to implement migration for the tables by creating a new version (check apple's documentation here: Lightweight Migration)
Otherwise if you don't change anything updating the app would not make the user lose any data.
We are trying to create an iPhone application that will automatically receive data from a database. Which is a database that will work with Xcode. Our goal is that users can go to our website and input information. That data will be recorded to a database. Once the user downloads our app, the info should then be retrieved from the database and included in the app. We are wondering what database is suitable. It must be able to receive information from a website AND submit it to an application.
You're unlikely to find a iOS "aware" database that can automatically sync content over the internet.
However, you can of course obtain the data over the internet yourself and then insert it into the local database on the device, in which case the popular (and supported out of the box) SQLite would seem like an obvious choice.
As #Deepak also suggests, you could use Core Data which is a (sort-of, ish) ORM that can automatically use SQLite as it's underlying storage mechanism.
The solution that most people use in this case is to use an RDBMS like MySQL and build a web-service layer on top of the database for the entities that your iPhone app is interested in.
This way, when a user goes to the web-app, they can add the data that you allow them to add there, and later on they can access the same data from the iPhone app via the web-service layer also.
Couchbase's new iOS-Couchbase framework is in beta right now - all the functionality of Apache CouchDB on your favourite developer platform - at https://github.com/couchbaselabs/iOS-Couchbase. the iOS release is new but we're looking for it to go places!
Its awesome sync abilities would allow you to pull down any relevant content from your website via HTTP/JSON, or further formats using shows and lists if needed. Pushing data the other way is just as easy. Sync can be continuous, or on demand, bidirectional or one way.
Take a look at some of the Couch App frameworks (not for iOS but for your website)
http://techzone.couchbase.com/community/articles/couchdb/recipes
http://www.mail-archive.com/user#couchdb.apache.org/msg13928.html lots of comments on this thread
A+
Dave