ios - Get notified in the background when app's "location" and "background app refresh" permissions change -
does know if app can notified in background system when app permissions change? i'm interested in getting notified when user changes "location" permission , "background app refresh" permission.
so far have looked call-back method:
locationmanager(manager: cllocationmanager!, didchangeauthorizationstatus status: clauthorizationstatus)
however, app doesn't notified in background.
i tried adding observer notification:
uiapplicationbackgroundrefreshstatusdidchangenotification
but can't work either.
here's code:
func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { nsnotificationcenter.defaultcenter().addobserver(self, selector: "checkbackgroundpermission", name: uiapplicationbackgroundrefreshstatusdidchangenotification, object: nil) locationmanager = cllocationmanager() locationmanager.delegate = self locationmanager.pauseslocationupdatesautomatically = false if(locationmanager.respondstoselector("requestalwaysauthorization")) { locationmanager.requestalwaysauthorization() } if launchoptions?[uiapplicationlaunchoptionslocationkey] != nil { locationmanager = cllocationmanager() locationmanager.delegate = self locationmanager.pauseslocationupdatesautomatically = false let prefs:nsuserdefaults = nsuserdefaults.standarduserdefaults() let uuidstring = prefs.stringforkey("uuid") string! let uuid : nsuuid? = nsuuid(uuidstring: uuidstring string) beaconregiongeneral = clbeaconregion(proximityuuid: nsuuid(uuidstring: uuidstring), identifier: "general") locationmanager.startrangingbeaconsinregion(beaconregiongeneral) setisranging(true) } if(application.respondstoselector("registerusernotificationsettings:")) { application.registerusernotificationsettings( uiusernotificationsettings( fortypes: uiusernotificationtype.alert | uiusernotificationtype.sound, categories: nil ) ) } return true } func checkbackgroundpermission() { sendlocalnotificationwithmessage("checkbackgroundpermission", playsound: false) println("checkbackgroundpermission") } func locationmanager(manager: cllocationmanager!, didchangeauthorizationstatus status: clauthorizationstatus) { sendlocalnotificationwithmessage("didchangeauthorizationstatus", playsound: true) println("didchangeauthorizationstatus") }
you can use below delegate method (from cllocationmanagerdelegate protocol) notifications.
optional func locationmanager(_ manager: cllocationmanager!, didchangeauthorizationstatus status: clauthorizationstatus)
Comments
Post a Comment