mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 03:01:51 +08:00
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:
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user