gpt4 book ai didi

cordova - ionic 恢复暂停事件防止文件浏览时触发,仅在按下主页按钮时触发

转载 作者:行者123 更新时间:2023-12-02 21:07:22 25 4
gpt4 key购买 nike

我正在开发一个聊天应用程序,我在暂停和恢复事件时使用。

document.addEventListener('暂停',onpause, false);

document.addEventListener('resume' , onresume,false);

当我打开应用程序并按 Android 手机的主页按钮时,此事件完美运行,这些事件非常完美。但我的问题是,在聊天应用程序中,当我选择手机图片库的浏览按钮时,我会从图库发送文件附件,同时暂停事件会触发。当我在图像库中未选择任何图像时,当我单击主页按钮时,同一事件不会触发。那么我如何在从图库中选择文件时防止暂停事件。

ionic 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;
}
}

画廊调用也包含在服务中。每次调用它时,我都会“暂停”事件并在用户交互完成后“继续”事件:

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();
}

最后一步:我不再监听resume事件,而是订阅resume Oberservable:

        this.eventService.resume().subscribe(() => {
this.statusBar.hide();
});

关于cordova - ionic 恢复暂停事件防止文件浏览时触发,仅在按下主页按钮时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42282721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com