Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 我如何在爱奥尼亚内部通过对讲机实现登录检查承诺?_Angular_Typescript_Ionic Framework_Ionic2_Intercom - Fatal编程技术网

Angular 我如何在爱奥尼亚内部通过对讲机实现登录检查承诺?

Angular 我如何在爱奥尼亚内部通过对讲机实现登录检查承诺?,angular,typescript,ionic-framework,ionic2,intercom,Angular,Typescript,Ionic Framework,Ionic2,Intercom,我正在使用Ionic 2构建一个移动应用程序。应用程序使用对讲机(-) 根据集成说明,我正在app.component.ts文件中的app boot上注册身份不明的用户。这个很好用 为了识别已注册的用户,我需要从存储器中提取一些项目(用户ID和电子邮件地址)。这使用承诺,异步也是如此。进行此操作时,对讲机不会注册用户。如果我只是用硬编码的值正常地调用用户,而不是查询存储,那么它就可以正常工作 设备上的存储速度非常快,在启动屏幕加载期间,我只需要在应用程序启动时执行一次,所以我很高兴让应用程序在p

我正在使用Ionic 2构建一个移动应用程序。应用程序使用对讲机(-)

根据集成说明,我正在
app.component.ts
文件中的app boot上注册身份不明的用户。这个很好用

为了识别已注册的用户,我需要从存储器中提取一些项目(用户ID和电子邮件地址)。这使用承诺,异步也是如此。进行此操作时,对讲机不会注册用户。如果我只是用硬编码的值正常地调用用户,而不是查询存储,那么它就可以正常工作

设备上的存储速度非常快,在启动屏幕加载期间,我只需要在应用程序启动时执行一次,所以我很高兴让应用程序在promise运行时等待。这可能吗?或者,我是不是完全错了

下面app.component.ts`中的我的代码:

platform.ready().then(() => {
  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  statusBar.styleDefault();
  splashScreen.hide();

  // This works
  intercom.registerUnidentifiedUser({});

  // This also works
  intercom.registerIdentifiedUser({
    userId: '987654321',
    email: 'foobar@example.com'
  });

  // This does not work
  storage.get('user_id').then((user_id) => {
    storage.get('email').then((email) => {
      intercom.registerIdentifiedUser({
        userId: user_id,
        email: email
      });
    });
  });
});
因为对讲机是本机库,我需要在设备上测试,所以我没有错误日志。如果我将
console.log
s放在存储器中,我可以看到适当的值,所以不是这样

在此重申我的问题:

我是否需要防止存储调用是异步的,如果需要,如何防止


或者,我是不是走错了路?Intercom文档明确指出,这是一种检查用户是否已登录,然后适当调用
registerUnidentifiedUser
registerIdentifiedUser
的情况,我相信我是在遵循最佳实践,将用户数据存储在
存储器中

您不能使其不异步。不过,一个解决办法是尝试使用
localStorage
,看看这是否有效
localStorage
不是异步的,您将使用以下方法获得值:
let user\u id=localStorage.getItem('user\u id')但它确实比我相信的
存储
更不安全。设置只是
localStorage.setItem('user\u id',XXX)
localStorage
不鼓励存储用户数据,因为操作系统倾向于定期擦除数据(存储空间不足,RAM不足,如果您的应用程序已被备份一段时间,以及其他一些原因)。使用
存储
是本地存储用户数据的公认方法。你认为它没有运行还有其他原因吗?没有线索,从未使用过图书馆。您可以尝试先检索
用户id
电子邮件
,然后在超时时间内添加
对讲机
通话。因为存储速度太快了。