The application.ios.addNotificationObserver method now returns an observer object which you should supply as the first argument when calling app.ios.removeNotificationObserver. (Fixed #473)

This commit is contained in:
Rossen Hristov
2015-09-01 12:34:20 +03:00
parent 007360fc76
commit 7a2e41b1b3
6 changed files with 25 additions and 36 deletions

View File

@ -2,13 +2,4 @@
application.mainModule = "main-page";
application.on(application.exitEvent, () => {
if (application.android) {
application.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED);
}
else {
application.ios.removeNotificationObserver(UIDeviceBatteryLevelDidChangeNotification);
}
});
application.start();

View File

@ -5,6 +5,16 @@ import labelModule = require("ui/label");
var batteryLabel: labelModule.Label;
var registered = false;
var batteryObserver: any;
application.on(application.exitEvent, () => {
if (application.android) {
application.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED);
}
else {
application.ios.removeNotificationObserver(batteryObserver, UIDeviceBatteryLevelDidChangeNotification);
}
});
export function onPageLoaded(args: observable.EventData) {
var page = <pages.Page>args.object;
@ -34,7 +44,7 @@ export function onPageLoaded(args: observable.EventData) {
}
UIDevice.currentDevice().batteryMonitoringEnabled = true;
onReceiveCallback(null);
application.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, onReceiveCallback);
batteryObserver = application.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, onReceiveCallback);
}
registered = true;
}