该平台不支持该方法。

3

我正在使用forge.prefs.get来获取缓存的用户令牌,在iOS和Web上运行良好。我使用backbone.js来渲染所有内容。 在Android上,当尝试使用相同的调用时,我会收到以下错误:

[DEBUG] Native call prefs.get with task.params: {"key":"user"}
[DEBUG] Native call notification.hideLoading with task.params: {}
[INFO] --------- beginning of /dev/log/system
[DEBUG] Returned: {"content":{"message":"Method not supported on this platform","type":"UNAVAILABLE","subtype":null},"callid":"4B01A334-2DC4-4511-A029-2C9D9B131D8C","status":"error"}

运行模拟器时,我得到了这个结果。如果我编译 APK 并安装它,代码将默默失败,并且用户将卡在登录界面。

以下是获取用户信息的代码:

     forge.prefs.get('user', function(user){ //success
      if(user === null){
        alert('USER not found');
        App.ViewManager.Login();
      }else{
        var u = JSON.parse(user);
        forge.logging.info(u);
        forge.logging.info(u.authentication_token);
        App.Utils.authToken = u.authentication_token;
        App.ViewManager.Companies();
      }
    })

这用于存储数据:

forge.prefs.set('user', JSON.stringify(data), function(){},function(){});

在iOS和Web版本中,这个功能完美运行。有什么想法,为什么在安卓4.4上的模拟器中会出现问题?我使用的是Trigger toolkit 2.1.3版本和prefs模块2.0版本。


可能是解析JSON时出现的不支持的方法错误的重复问题。 - Paul Sweatte
1个回答

0

当使用forge.prefs.setforge.prefs.get时,您不需要对数据进行stringifyparse操作。数据会自动存储为JSON对象,因此请尝试将您的代码更改为:

forge.prefs.set( 'user', data );

同时也要删除 JSON.parse(user); 这一行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接