Is It Possible To Build Offline-first Mobile Apps Using Aws Appsync?
I'd like to use AWS AppSync for mobile development (Android/iOS) but I’m not sure about its offline capabilities. According to the documentation the data will be accessible while
Solution 1:
It should be possible with Firestore, AWS AppSync or your own Backend solution. Any approach you use, you will control when you want to start saving/syncing things online.
You need to handle all this while designing this app. Suggested approach
Let's take example of simple ToDo app
I will let User add & save Todos in app
All this data will be persisted on disk(using SQLLITE, Preferences or File etc.)
- If User does clear data or reinstall app, all this data is lost
- If User wants to go premium, I will let him sync this data with my Backend solution(any one of above-mentioned solution)
Example implementation using Android Shared preference as local storage
publicvoidsaveLocalTodo(String title, String details) {
ArrayList<Todo> todos;
Todo todo = newTodo(title, details);
String listOfTodo = sharedPreference.getString(TODOS_LIST, null);
if (listOfTodo == null)
todos = newArrayList<Todo>();
else
todos = gson.fromJson(listOfTodo, newTypeToken<ArrayList<Todo>>() {
}.getType());
//save at 0th position, recent should always come first
todos.add(0, todo);
sharedPreference.edit().putString(TODOS_LIST, gson.toJson(todos)).apply();
}
publicArrayList<Todo> getLocalTodos() {
ArrayList<Todo> todos;
String listOfTodos = sharedPreference.getString(TODOS_LIST, null);
if (listOfTodos == null)
todos = newArrayList<Todo>();
else
todos = gson.fromJson(listOfTodos, newTypeToken<ArrayList<Todo>>() {
}.getType());
return todos;
}
publicvoidsaveOnBackend() {
// Connect to Backend solution// Get all local todos from preference// Save all at once in batches//OR// Get all local todos from preference// Save one by one
}
Solution 2:
Use Realm Database to manage all offline and online data and save if the application uninstall
Solution 3:
you can read https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-reactnative.html
AWS AppSync support offline mode and you can use data base for your app
Post a Comment for "Is It Possible To Build Offline-first Mobile Apps Using Aws Appsync?"