import { Component } from "@angular/core" ; import { Application , isAndroid , isIOS } from "@nativescript/core" ; @ Component ( { moduleId : module . id , templateUrl : "./app-using-ios-specifics.component.html" } ) export class AppUsingIosExampleComponent { public isItemVisible : boolean ; public batteryLife : number ; public goodToRemove : boolean = false ; constructor ( ) { if ( isIOS ) { let delegate = Application . ios . delegate ; let nativeApp = Application . ios . nativeApp ; let rootController = Application . ios . rootController ; let window = Application . ios . window ; this . isItemVisible = true ; this . batteryLife = 0 ; UIDevice . currentDevice . batteryMonitoringEnabled = true ; this . batteryLife = + ( UIDevice . currentDevice . batteryLevel * 100 ) ; let that = this ; let observer = Application . ios . addNotificationObserver ( UIDeviceBatteryLevelDidChangeNotification , function onReceiveCallback ( notification ) { that . batteryLife = + ( UIDevice . currentDevice . batteryLevel * 100 ) ; } ) ; if ( this . goodToRemove ) { Application . ios . removeNotificationObserver ( observer , UIDeviceBatteryLevelDidChangeNotification ) ; } } else if ( isAndroid ) { this . isItemVisible = false ; } } }