是否可以使用 AWS AppSync 构建离线优先的移动应用程序?

Is it possible to build offline-first mobile apps using AWS AppSync?(是否可以使用 AWS AppSync 构建离线优先的移动应用程序?)
本文介绍了是否可以使用 AWS AppSync 构建离线优先的移动应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想使用 AWS AppSync 进行移动开发 (Android/iOS),但我不确定它的离线功能.

I'd like to use AWS AppSync for mobile development (Android/iOS) but I’m not sure about its offline capabilities.

根据文档,数据将在离线时可访问,如果客户端再次在线,数据将自动同步.但在使用 AppSync 创建和修改离线数据之前,我找不到有关应用程序客户端是否需要先连接到 AWS 的任何信息.

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.

我不熟悉 AppSync 的底层技术(例如 GraphQL),而且我无法访问公共预览版来自己测试它.

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.

我想让对隐私敏感的用户能够在不连接到 AWS 的情况下使用应用程序,同时仍然能够将 AppSync 用作离线数据库.只有当用户后来决定跨设备使用备份/同步数据时,他或她才能选择连接到 AWS.

AWS AppSync 能否实现此用例?

Will this use case be possible with AWS AppSync?

不使用任何其他本地存储(如 SharedPreferences、SQLite、Realm 等)

推荐答案

Firestore、AWS AppSync 或您自己的后端解决方案应该可以实现.您使用的任何方法都可以控制何时开始在线保存/同步内容.

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

我们以简单的 ToDo 应用程序

  • 我会让用户添加 &在应用中保存待办事项

  • I will let User add & save Todos in app

所有这些数据都将保存在磁盘上(使用 SQLLITE、首选项或文件等)

All this data will be persisted on disk(using SQLLITE, Preferences or File etc.)

示例使用Android共享偏好作为本地存储实现

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
}

这篇关于是否可以使用 AWS AppSync 构建离线优先的移动应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How To Create a Rotating Wheel Control?(如何创建转轮控件?)
iOS 6 rotations: supportedInterfaceOrientations doesn#180;t work?(iOS 6 旋转:supportedInterfaceOrientations 不起作用?)
CABasicAnimation rotate returns to original position(CABasicAnimation 旋转返回原始位置)
How to avoid restarting activity when orientation changes on Android(如何在 Android 上的方向更改时避免重新启动活动)
UITabBarController Rotation Issues in ios 6(ios 6 中的 UITabBarController 旋转问题)
iOS: How to run a function after Device has Rotated (Swift)(iOS:设备旋转后如何运行函数(Swift))