我在iOS上使用原生Salesforce SDK来离线存储数据并与服务器同步。我可以更新smartstore数据库的条目。当我需要同步时,我无法在SmartStore API中找到允许我将数据上传到salesforce服务器的方法。你能指出我如何实现这个目标的正确方向吗?
答案 0 :(得分:1)
Ther不是smartstore sdk中的方法。你应该这样做:
/**
* Upload Queue to Salesforce
**/
OfflineQueue.UploadQueue = function(callback,error) {
console.log("OfflineQueue.UploadQueue");
if(Util.checkConnection()) {
console.log("OfflineQueue.UploadQueue -- app is online");
//DF12 DEMO 23 -- UPLOAD QUEUE TO SFDC
navigator.smartstore.soupExists('Queue',function(param){
if(param)
{
console.log("OfflineQueue.UploadQueue -- Queue exists");
OfflineQueue.LoadRecordsFromQueue(function(records) {
if(records.length==0){
console.log("OfflineQueue.UploadQueue -- no records in queue");
callback();
}
else {
console.log("OfflineQueue.UploadQueue -- iterating records");
for(i in records){
forcetkClient.update('Password__c',records[i].Id,{"Username__c":records[i].Username__c,"Password__c":records[i].Password__c,"Name":records[i].Name,"URL__c":records[i].URL__c},function(){
console.log('QUEUED SFDC Update Success!');
//DF12 DEMO 24 -- ON SUCCESS, REMOVE RECORD FROM QUEUE
navigator.smartstore.removeFromSoup('Queue',[records[i]._soupEntryId],function(){
console.log('Removed from Soup');
if(i == records.length-1) {
callback();
}
},error);
},error);
}
}
},error);
}
else {
console.log("Offline queue doesn't exist yet... must not be any records there...")
callback();
}
},error);
}
else {
console.log("We're offline, can't upload queue... how'd we even get here?")
callback();
}
}
github上有一个完整的smartsore汤和forcetk样本https://github.com/tomgersic/HazyPassword
我正在使用插件来封装这个基本流程。