【问题标题】:Is there a way to identify platform.resume event was called by camera?有没有办法识别 platform.resume 事件被相机调用?
【发布时间】:2017-02-09 10:33:19
【问题描述】:

我的 ionic v2 应用程序有问题,我已在 app.component.ts 订阅了 platform.resume,在此我有一个重定向,根据用户状态,每次拍照并且应用程序从相机返回时 platform.resume 是调用并且重定向中断了我的应用程序流程。有没有办法识别cordova-plugin-camera调用的resume事件?

【问题讨论】:

  • 我想不出你会根据 platform.resume 重定向的用例..
  • 令牌验证,重定向回登录页面
  • 我一般使用Events来触发这样的动作。我从未使用过平台简历

标签: android ios cordova ionic2 cordova-plugins


【解决方案1】:

令牌验证,重定向回登录页面

我建议你使用Events 来触发基于登录/注销的重定向

 events.publish('token:received', token);

在你的 app.component.ts 中

events.subscribe('token:received',(token)=>{
  //redirect
});

platform.resume 这样的内部函数可以被任意数量的插件或组件在内部使用。

【讨论】:

  • 感谢全面的建议,我明天早上测试一下
  • 您知道cordova-camera-plugin 使用的某种参数或标识符是否可以在简历中实际使用?我认为这将是一个可用的功能,如果它存在的话。
  • 我确实找到了github.com/driftyco/ionic/blob/…,看起来任何cordova插件都可以通过平台生命周期钩子与ionic交互
  • 有道理。无论如何,插件都需要在 platform.ready() 中使用
【解决方案2】:

如果我没看错,你可以使用返回的承诺,然后重定向到另一个页面。

Camera.getPicture(options).then((imageData) => {
  let base64Image = 'data:image/jpeg;base64,' + imageData;
  this.NavCtrl.push(TheRedirectPage, ParamsYouDLikeToPass);
  // i think you can also call platform.resume here, if you want, but i'd stick with the promise return.
}, (err) => {
  // Handle error
});

无需与platform.resume 核对,因为当它从相机返回时,一切准备就绪。

【讨论】:

  • 我不会在相机响应中调用 platform.resume,我已经在 app.component.ts 上订阅了它,所以它会被间接调用。
猜你喜欢
  • 2013-02-17
  • 1970-01-01
  • 2017-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多