Ionic-native: Native BackgroundMode add EventListener does not work

Created on 16 Aug 2016  路  8Comments  路  Source: ionic-team/ionic-native

_From @mburger81 on August 16, 2016 9:26_

As described here in my post in the forum, I can not add an listener to activate

https://forum.ionicframework.com/t/error-on-backgroundmode-on/58979/4

using ionic2 beta.11

BackgroundMode.on('activate', function() {
});

EXCEPTION: TypeError: Cannot read property 'apply' of undefined
browser_adapter.js:84 EXCEPTION: TypeError: Cannot read property 'apply' of undefinedBrowserDomAdapter.logError @ browser_adapter.js:84BrowserDomAdapter.logGroup @ browser_adapter.js:94ExceptionHandler.call @ exception_handler.js:65(anonymous function) @ application_ref.js:337EventEmitter.subscribe.schedulerFn @ async.js:139SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:127NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:124NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:74ZoneDelegate.handleError @ zone.js:327Zone.runTask @ zone.js:259ZoneTask.invoke @ zone.js:423
browser_adapter.js:84 STACKTRACE:BrowserDomAdapter.logError @ browser_adapter.js:84ExceptionHandler.call @ exception_handler.js:67(anonymous function) @ application_ref.js:337EventEmitter.subscribe.schedulerFn @ async.js:139SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:127NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:124NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:74ZoneDelegate.handleError @ zone.js:327Zone.runTask @ zone.js:259ZoneTask.invoke @ zone.js:423
browser_adapter.js:84 TypeError: Cannot read property 'apply' of undefined
    at callCordovaPlugin (plugin.js:81)
    at Function.exports.wrap (plugin.js:221)
    at Function.value [as on] (plugin.js:284)
    at SafeSubscriber._next (app.ts:70)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:225)
    at SafeSubscriber.next (Subscriber.js:174)
    at Subscriber._next (Subscriber.js:124)
    at Subscriber.next (Subscriber.js:88)
    at XMLHttpRequest.XHRConnection.response.Observable_1.Observable.onLoad (xhr_backend.js:68)
    at ZoneDelegate.invokeTask (zone.js:356)BrowserDomAdapter.logError @ browser_adapter.js:84ExceptionHandler.call @ exception_handler.js:68(anonymous function) @ application_ref.js:337EventEmitter.subscribe.schedulerFn @ async.js:139SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:127NgZone._zoneImpl.ng_zone_impl_1.NgZoneImpl.onError @ ng_zone.js:124NgZoneImpl.inner.inner.fork.onHandleError @ ng_zone_impl.js:74ZoneDelegate.handleError @ zone.js:327Zone.runTask @ zone.js:259ZoneTask.invoke @ zone.js:423
plugin.js:81 Uncaught TypeError: Cannot read property 'apply' of undefined

_Copied from original issue: driftyco/ionic#7736_

bug

Most helpful comment

Just added the new methods to this plugin along with a new @CordovaFunctionOverride decorator that handles situations where the plugin author expects developers to override a function in the plugin, like BackgroundMode.onactivate = function() {}. Instead, the plugin wraps that in an observable and handles it for you.

All 8 comments

I am seeing a similar issue as well.

"EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined"

I've run into the same problem. Is just the documentation wrong (there is no second paramater in the documentation!) or is the implementation of that function erroneous? Anyway the current situation does not work.

Sorry about that. The method on doesn't actually exist in the plugin's API. Not sure if it was a mistake when the wrapper was written or the developer has changed the API.

I will edit the wrapper soon to implement the correct methods.

Just added the new methods to this plugin along with a new @CordovaFunctionOverride decorator that handles situations where the plugin author expects developers to override a function in the plugin, like BackgroundMode.onactivate = function() {}. Instead, the plugin wraps that in an observable and handles it for you.

stupid beginner question... how do I get the fix into my app?

Problem that the version 2.0.3 is compatible with typescript 2.0 and ionic-angular 2.0.0-beta11 is not, only in beta.12 which will be launched soon.

ok, thanks for that :-) I'll just need to be patient!

@mlynch When will your fix be released?

Ok as a temporary fix for other devs: https://forum.ionicframework.com/t/how-to-use-cordova-plugin-backgroundmode-in-ionic-2-with-typescript/55278/3?u=cyberto

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hobbydevs picture hobbydevs  路  3Comments

kyleap picture kyleap  路  4Comments

goleary picture goleary  路  3Comments

ihadeed picture ihadeed  路  4Comments

danbucholtz picture danbucholtz  路  3Comments