Ion resumption of pause event prevent from fire by file view only fire when the home button is pressed

I am developing a chat application in which I use pause and resume event.

document.addEventListener ('pause', onpause, false);

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

This event works great when I open the application and press the home button on the Android phone, these events are perfect. But my problem is that in the chat application I send file attachments from the gallery when I select the browse button, the phone’s image gallery, and at the same time, pauses are fire. while I am in the image gallery without selecting any images at the same time, when I press the home button, the same event does not fire. Since I can prevent a pause event when selecting a file from the gallery.

Is there any other way to do this in ionic v1 ? Or how can I start a pause and resume an event for this.

+7
cordova cordova-plugins ionic-framework
source share
3 answers

I wrote a small Service to solve this problem:

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

A gallery call is also wrapped in a service. Each time I call it, I “stop” the event and “continue” it after the user interaction is completed:

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

Last step: instead of listening to the resume event, I subscribe to the Oberservable summary:

  this.eventService.resume().subscribe(() => { this.statusBar.hide(); }); 
+2
source share

You can delete the pause event before opening the gallery and reattach the event to the gallery’s return message.

 document.removeEventListener("pause", myFunction); 
+1
source share

I'm not sure if you are using Ionic 1 or 2, but there are life cycle events for both versions.

Here are the ones for Ionic 2 (scroll down to "Life Cycle Events") https://ionicframework.com/docs/api/navigation/NavController/

Here are the ones for Ionic 1 https://forum.ionicframework.com/t/order-of-lifecycle-events/28251/2

+1
source share

All Articles