IOS (Swift 3) How to trigger broadcast receiver when gps is turn on/off?

问题内容:

Hello Friends

I am android(java/kotlin) and IOS(Swift) Developer. So I can easily get broadcast of GPS Enable/Disable in Android. But problem is in IOS platform.

If user Enable or Disable GPS from phone settings. Is any way to get callback to detect enabling/disabling GPS from my app.

问题评论:

    
you can get location permission is granted or not for application. I think that is the solution. You can check whether user allow location permission or not. You can check in application become active method if user manually enabled or disabled location service for app

答案:

答案1:

If user updates location services permission in settings and then enters the app (that was still loaded in memory), your CLLocationManagerDelegate implementation should receive authorization status update in function:


func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)

If you want to make action after first authorization positive change, just persist previou state somehow into user defaults or other persisting options

答案评论:

    
Thanks its worked
– Deepak Ror
9 hours ago

原文地址:

https://stackoverflow.com/questions/47713002/ios-swift-3-how-to-trigger-broadcast-receiver-when-gps-is-turn-on-off

添加评论

友情链接:蝴蝶教程