Check if App is Using DevAPP

165 views Asked by At

I’m trying to figure out how to check if my Ionic app is running on DevAPP (DevAPP is a testing platform that runs your app locally on your device).

This is important because I’m using a plugin that is not available in DevAPP, so it crashes the app. I want to be able to perform some kind of check to see if the app is being run with DevAPP. And, if it is, I just won’t call the code for the unavailable plugin.

I’ve tried checking platform.platforms(), but it just says “mobile,android,phablet,mobileweb”. Those don’t seem to suggest that DevAPP is running.

Another possible solution would be a way to check if a plugin is installed. I tried just checking if the injected variable was truthy if( this.fcm ), but this still crashes the app.

1

There are 1 answers

0
Blake McGillis On BEST ANSWER

All right. Well, I wasn't able to figure out how to specifically check within the code whether or not the app is currently running on DevAPP. But I did manage to find a solution to my problem. It was actually pretty straight-forward.

Since the native plugin I was trying to use returns a promise, I just used the .catch() method available on promises:

this.fcm.getToken().then( token => {
    console.log( 'token: ', token ); //@DEBUG
})
.catch( error => { // Catch error that FCM is not available in DevAPP and web
    console.log( 'Error Getting FCM Token: ', error ); //@DEBUG
});

This can also work with Observables by processing the error response option:

this.fcm.onNotification().subscribe( 
    data => {
        console.log( 'data: ', data ); //@DEBUG
    },
    error => {
        console.log( 'Error Subscribing to FCM Notification: ', error ); //@DEBUG
    }
); 

After implementing this code, my app no longer crashed while running in DevAPP.