swift - How to get notified when iPhone battery is at 10% -
i'm building apple watch app let see iphone
battery level, code battery level:
uidevice.currentdevice().batterymonitoringenabled = true batterylevel = uidevice.currentdevice().batterylevel
now how can call notification when iphone
battery @ 10%? thanks
this objective-c translated swift:
[[uidevice currentdevice] setbatterymonitoringenabled:yes]; float battery = [[uidevice currentdevice] batterylevel]; if (battery < alertlevel) { //send notification }
how send uilocalnotification
uilocalnotification *notification = [[uilocalnotification alloc] init]; notification.firedate = [nsdate datewithtimeintervalsincenow:0]; notification.alertbody = @"warning!"; notification.timezone = [nstimezone defaulttimezone]; notification.soundname = uilocalnotificationdefaultsoundname; notification.applicationiconbadgenumber = 0; nsdictionary *infodict = [nsdictionary dictionarywithobject:@"low battery!" forkey:@"notification"]; notification.userinfo = infodict; [[uiapplication sharedapplication] schedulelocalnotification:notification];
Comments
Post a Comment