我在使用Kapsel OData插件在設備脫機時從商店檢索數據時遇到困難。Cordova Windows項目中的離線數據檢索
這裏的情況是:
- 科爾多瓦應用Windows平臺
- 當應用程序打開時,我通過對我的OData服務開店(類似於羅斯文服務)啓動
- 商店被創建並打開。然後,我嘗試使用OData.read或通過設置模型,然後在其上調用read()從商店檢索數據。
- 該商店將成功打開。但是,當設備處於聯機狀態時,我讀取數據的呼叫會成功,並且在脫機時會失敗,無論以前使用的兩種方法中的哪一種。
這裏是我的代碼:
function openStore() {
var properties = {
"name": "Emergency",
"host": applicationContext.registrationContext.serverHost,
"port": applicationContext.registrationContext.serverPort,
"https": applicationContext.registrationContext.https,
"serviceRoot": appId,
"definingRequests": {
"Products": "/Products"
}
};
store = sap.OData.createOfflineStore(properties);
store.open(openStoreSuccessCallback, errorCallback);
}
function openStoreSuccessCallback() {
sap.OData.applyHttpClient();
retrieveWithModel();//retrieveWithOData();
}
function retrieveWithModel() {
var uri = applicationContext.applicationEndpointURL;
var user = applicationContext.registrationContext.user;
var password = applicationContext.registrationContext.password;
var headers = { "X-SMP-APPCID": applicationContext.applicationConnectionId };
var oModel = new sap.ui.model.odata.ODataModel(uri, {
json: "true",
user: user,
password: password,
headers: headers
});
sap.ui.getCore().setModel(oModel);
oModel.read("/Products", {
success: function (oEvent) {
var msg = new Windows.UI.Popups.MessageDialog("Success");
msg.showAsync();
},
error: function (err) {
console.log("you have failed");
var msg = new Windows.UI.Popups.MessageDialog("Fail");
msg.showAsync();
}
});
}
function retrieveWithOData() {
var sURL = applicationContext.applicationEndpointURL + "/Products";
var oHeaders = {};
oHeaders['Authorization'] = authStr;
oHeaders['X-SMP-APPCID'] = applicationContext.applicationConnectionId;
//oHeaders['Content-Type'] = "application/json";
//oHeaders['X-CSRF-Token'] = "FETCH";
var request = {
headers: oHeaders,
requestUri: sURL,
method: "GET"
};
OData.read(request,
function (data, response) {
console.log('Success');
},
function (err) {
console.log('Fail');
}
);
}
- Kapsel SDK版本是3.8.0
- SMP SDK是SP08
- 科爾多瓦版本5.3.3
我想知道這是否是應用程序啓動方式的問題。我需要一種方法來每次打開應用程序的相同實例,因此脫機存儲將保留其所有數據。由於Cordova生成的Visual Studio項目不生成.exe文件(只有.appx文件需要進行簽名和側載才能使用),我繼續的方式是:我從Visual Studio在聯機模式下運行應用程序,然後將其固定到任務欄或開始菜單,關閉它並將設備切換到離線模式,然後從任務欄重新打開它。 但是,越來越多的似乎這種方法不能按預期工作。
任何人都可以確認從任務欄打開的Visual Studio項目應該以與從VS運行時相同的方式運行,具有相同的依賴項,庫等?如果是這種情況(我真的不能想象爲什麼它不會),有沒有人有這些技術的經驗,看看有什麼潛在的問題?
任何幫助將不勝感激。 謝謝!