問題描述
我想使用 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 構建離線優先的移動應用程序?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!