Pri*_*ish 7 cordova ionic-framework cordova-plugins
我正在开发一个聊天应用程序,我正在使用暂停和恢复活动.
document.addEventListener('pause',onpause,false);
document.addEventListener('resume',onresume,false);
当我打开应用程序并按下主屏幕按钮到Android手机时,此活动非常完美.但我的问题是,在聊天应用程序中,当我选择浏览按钮电话图像库时,我从图库发送文件附件,同时暂停事件是火.当我在图像库中没有选择任何图像时,当我点击主页按钮时,同一事件没有被触发.那么我如何在从库中选择文件时阻止暂停事件.
在离子v1中有没有其他方法可以做到这一点?或者我如何在暂停和恢复活动中触发同样的事情.
我写了一个小服务来解决这个问题:
import {Injectable} from '@angular/core';
import {Subject} from "rxjs/Subject";
@Injectable()
export class EventService {
protected resumeHalted = false;
protected resumeSubject = new Subject<any>();
protected resumeListener = () => {
if (this.resumeHalted) {
return;
}
this.resumeSubject.next();
};
constructor() {
document.addEventListener('resume', this.resumeListener);
}
haltResume() {
this.resumeHalted = true;
}
continueResume() {
this.resumeHalted = false;
}
resume() {
return this.resumeSubject;
}
}
Run Code Online (Sandbox Code Playgroud)
画廊电话也包含在一项服务中。每次我调用它时,我都会“暂停”事件并在用户交互完成后“继续”事件:
getPicture(options: CameraOptions) {
let subject = new Subject<any>();
this.eventService.haltResume();
this.camera.getPicture(options).then((path) => {
// ...
subject.next();
subject.complete();
this.eventService.continueResume();
}, () => {
this.eventService.continueResume();
});
return subject.asObservable();
}
Run Code Online (Sandbox Code Playgroud)
最后一步:我不再监听resume事件,而是订阅resume Oberservable:
this.eventService.resume().subscribe(() => {
this.statusBar.hide();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
753 次 |
| 最近记录: |