Events not firing in --release --prod mode


#1

Hi all
Could you help me understand why Event subscribe works in run mode, but doesn’t work in --release --prod mode?
Here example
…\src\app\app.component.ts

constructor(

public events: Events,

)

this.platform.ready().then(() => {
this.events.subscribe(‘user:registrationId’, (val) => {
this.registrationId = val;
});

…\src\providers\push\push.ts

@Injectable()
export class PushProvider {

constructor(

public events: Events,

registration firing and I get registration.registrationId value

pushObject.on(‘registration’).subscribe((registration: any) => {
this.events.publish(‘user:registrationId’, true);
});

but it doesn’t firing. Please help.


#2

Does it work without --release --prod?
Which one of the both is making it fail?

Also post your ionic info output please.


#3

Yes, when I start with

ionic cordova run android

It’s works, but doesn’t work

ionic cordova run android --prod --release

And Events doesn’t work with ios platform to
I have tested it on two different computers Windows 10 and IOS sierra. I was surprised when it didn’t work on production, when I deployed on Google play market and Apple store(((


#4

Hi

Why are you putting the event-subscribe in platform.ready? I would think that isnt necessary

Rgdz

Tom


#5

$ ionic info

cli packages: (C:\Projects\MCisp\node_modules)

@ionic/cli-utils : 1.12.0
ionic (Ionic CLI) : 3.12.0

global packages:

cordova (Cordova CLI) : 7.0.1

local packages:

@ionic/app-scripts : 2.1.3
Cordova Platforms : android 6.2.3 ios 4.4.0
Ionic Framework : ionic-angular 3.6.0

System:

Android SDK Tools : 25.2.3
Node : v6.11.2
npm : 3.10.10
OS : Windows 10

Misc:

backend : legacy


#6

Hi, thanks for the reply. Where do you recommend placing this.events.subscribe?


#7

Shiryakovs-Mac:MCisp shiryakov$ ionic info

cli packages: (/Users/shiryakov/Documents/MCisp/node_modules)

@ionic/cli-utils : 1.12.0
ionic (Ionic CLI) : 3.12.0

global packages:

cordova (Cordova CLI) : 7.0.1

local packages:

@ionic/app-scripts : 2.1.3
Cordova Platforms : android 6.2.3 ios 4.4.0
Ionic Framework : ionic-angular 3.6.0

System:

ios-deploy : 1.9.1
Node : v6.11.2
npm : 3.10.10
OS : macOS Sierra
Xcode : Xcode 8.3.3 Build version 8E3004b

Misc:

backend : legacy


#8

What does this mean? Have you put a console.log inside your subscription to make sure that line gets reached at runtime?


#9

You ignored this question:


#10

I’ve not tested separately prod and release. I thought you will answer me what am I doing wrong )


#11

I put in subscribe alert(1) function.


#12

Why isn’t that in the code you posted?


#13

I show a problem, before I posted that topic i removed alert


#14

How should we know that if we don’t even know what is actually causing the error?


#15

But I’m not getting an error, Events only not working. You asked me about prod and release, they can’t be together when calling the run or build method? I always publish the app with this modes.


#16

They can, but we have to narrow down which one is breaking events. Which is why @Sujan12 is requesting that you try each argument separately.


#18

Hi
Well In many places you can subscribe to the event system but because you subscribe dependent on the success of platform ready that may be a cause of your issue.

Maybe try to debug using a console write or even by showing a toast to see if code is reached

For what it is worth my current project subscribes to events in the constructor. And I am not making claims this being best practice, but it works for me.

Rgdz and happy debugging!

Tom


#19

Hi guys

The problem was not in the Event provider. I created a slide menu and fill it in the app.component.ts constructor, like this

 this.pages = [
 {title: 'Home', component: HomePage},
 {title: 'Messages', component: MessagesPage}
 ];

in app.html in *ngFor I’m drawing it

 <button menuClose ion-item *ngFor = "let p of pages" (click)="openPage(p)" style="position: relative; padding-left: 0px;">
   <span style = "padding-left: 16px;"> {{p.title}} </span>
   <span item-end *ngIf = "p.component.name == 'MessagesPage'" style = "color: red; float: right;" [ngClass] = "{'registraionIdTrue': registrationId}">
     <ion-icon name = "md-bulb" style = "color: red" [ngClass] = "{'registraionIdTrue': registrationId}"> </ ion-icon> Push
   </span>
 </button>

it appears in run mode without --prod --release, just

ionic cordova run anroid

p.component.name is equal to the component name and everything is ok

but with --prod mode like this

ionic cordova run anroid --prod

p.component.name = n !!! Just the “n” character.
the same will be in production file, when I use build instead run

Can anyone explain this???


#20

It saves on space and reduces the size of your final app file. You should never ever rely on component names.


#21

Hello,
Im having a similar issue with ngrx/state.
it’s definitely a tree-shaking error on the production build.
But I have no idea how to fix it.