offline data availability

I am building a phonegap app and use AWS Cognito to store the User data. In the description of Cognito, it is said, that the data is offline available. This does not work in my code:

var add_data;    
function getCognitoData(){
 var params = {
  IdentityPoolId: COGNITO_IDENTITY_POOL_ID,
  Logins: {
   'graph.facebook.com': FACEBOOK_TOKEN
  }  
 };
 AWS.config.region = AWS_REGION;
 AWS.config.credentials = new AWS.CognitoIdentityCredentials(params);
 AWS.config.credentials.get(function(err) {
  if (err) {
   console.log("Error: "+err);
   return;
  }
  console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);

  var syncClient = new AWS.CognitoSyncManager();

  syncClient.openOrCreateDataset('myDataset', function(err, dataset) {
   dataset.get('myKey', function(err, value) {
    console.log(value, err);
   });

   add_data = function(thisid, thisval) {
    dataset.put(thisid, thisval, function(err, record){
     dataset.synchronize({
      onSuccess: function(data, newRecords) {
       console.log("success", newRecords);
      },
      onFailure: function(err) {
       console.log("error", err);
      },
      onConflict: function(dataset, conflicts, callback) {
       console.log("sync conflict", dataset, conflicts);
       var resolved = [];

       for (var i=0; i<conflicts.length; i++) {
        resolved.push(conflicts[i].resolveWithRemoteRecord());
       }

       dataset.resolve(resolved, function() {
        return callback(true);
       });
      }
     });
    });
   }
  });
 });
}

The AWS Credentials for the Identity Pool and the Facebook Token are previously set, and work in the online mode, but I don't get the dataset data, when being offline.

Am I doing something wrong or is it generally not possible to get the Cognito Dataset data while being offline? I read, that the data is actually being held in the local storage.

I am using the current AWS SKD (Release v2.1.42) and the Amazon Cognito JS.


It's possible to get the data offline. You need to synchronize the dataset to get whatever contents may be inside, otherwise them being empty is expected. Are you doing that? If not, try doing that, but if so, can you update your code above?


There was a bug with the aws-sdk-js causing the offline bug. CognitoSync depends on aws-sdk-js . Should be working now as of aws-sdk-js@2.7.21 . Make sure you update.

链接地址: http://www.djcxy.com/p/41182.html

上一篇: 是否可以使用React创建离线的第一个应用程序

下一篇: 离线数据可用性