Is it possible to build offline-first mobile apps using AWS AppSync?

淺唱寂寞╮ 提交于 2019-12-03 09:41:07

问题


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 being offline and synced automatically if the client gets online again. But I can't find any information about if the app client needs to connect to AWS first, before using AppSync to create and modify offline data.

I'm not familiar with the underlying technologies of AppSync (e.g. GraphQL) and I don't have access to the public preview version to test it myself.

I would like to enable privacy-sensitive users to use an app without connecting to AWS while still being able to use AppSync as an offline database. Only if a user later decides to use backup/sync data across devices he or she can opt-in to connect to AWS.

Will this use case be possible with AWS AppSync?

Without using any other local storage (like SharedPreferences, SQLite, Realm, etc.)


回答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

public void saveLocalTodo(String title, String details) {
    ArrayList<Todo> todos;
    Todo todo = new Todo(title, details);
    String listOfTodo = sharedPreference.getString(TODOS_LIST, null);
    if (listOfTodo == null)
        todos = new ArrayList<Todo>();
    else
        todos = gson.fromJson(listOfTodo, new TypeToken<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();
}

public ArrayList<Todo> getLocalTodos() {
    ArrayList<Todo> todos;
    String listOfTodos = sharedPreference.getString(TODOS_LIST, null);
    if (listOfTodos == null)
        todos = new ArrayList<Todo>();
    else
        todos = gson.fromJson(listOfTodos, new TypeToken<ArrayList<Todo>>() {
        }.getType());
    return todos;
}

public void saveOnBackend() {
    // 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
}



回答2:


Use Realm Database to manage all offline and online data and save if the application uninstall




回答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



来源:https://stackoverflow.com/questions/47713306/is-it-possible-to-build-offline-first-mobile-apps-using-aws-appsync

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!