我正在使用 Ionic 2 构建移动应用程序。该应用程序使用对讲机(https://developers.intercom.com/docs/cordova-phonegap-installation - https://github.com/intercom/intercom-cordova)。
根据集成说明,我在app.component.ts文件中的应用程序启动时注册身份不明的用户。这工作正常。
为了识别注册用户,我需要从存储中提取一些项目(用户 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
});
});
});
});
因为 Intercom 是我需要在设备上测试的本地库,所以我没有错误日志。如果我将console.logs 放在存储承诺中,我可以看到适当的值,所以不是这样。
在这里重申我的问题:
我是否需要防止我的存储调用是异步的,如果需要,如何?
或者,我是否以错误的方式接近这个?对讲机文档明确指出,这是检查用户是否登录然后调用registerUnidentifiedUser或registerIdentifiedUser适当的情况,我相信我通过将用户数据存储在storage.