Switch on GPS automatically without user interaction - ios

Is it possible to switch on the GPS programmatically, without user interaction?

No it is not possible to turn on GPS without user interaction.

The first time you attempt to switch it on, there will be an Alert. After user has enabled it , then you can switch on/off at will.
see CLLocationManager
https://developer.apple.com/library/mac/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html

Related

Swift detect power button press event

Is it possible to somehow get a callback when the user presses on the physical power button on iOS? Just to make sure, I am not actually trying to change the behaviour of the power button, I just need to know when it was pressed.
Here is some extra info to explain why I need this callback. Our app uses a guided access mode to lock students in test and although guided access allows locking the device via the power button, that lock, unfortunately, causes our sockets to disconnect so we do not allow that. So what I need now is to detect the power button press so I can implement a fake lock in our app where I will dim the display and show a black image on top to save some battery power.

"CBCentralManager(delegate: self, queue: nil)" does not show Bluetooth popup message when Bluetooth is turned off from Control Center

I am trying to navigate the user to Bluetooth settings on a button click. CBCentralManager(delegate: self, queue: nil) works fine when Bluetooth is turned off from Settings App, but it is not working when Bluetooth is turned off from Control center e.g not showing the default Bluetooth popup.
Now I need to know if Bluetooth is turned off from the Control center so that I can show some custom popup message to the user.
Any help will be appreciated.
You are correct that the initialization option CBCentralManagerOptionShowPowerAlertKey, which should display a warning if the framework is initiated when bluetooth is turned off, does in fact not work as expected if bluetooth is toggled off from the Control Center. Since iOS 11 the system will actually not turn off bluetooth if you toggle off the button in Control Center, it only disconnects currently connected devices. The only way to turn off bluetooth then is to do it from System Settings. This is documented by Apple, but to me it is extremely misleading. So I honestly don't know if the API behavior you are experiencing is a bug, or if it is expected behavior.
My suggestion is that you skip this initialization option and instead rely on the value of central.state when you get the "centralManagerDidUpdateState:" callback and then create you own popup if the value is CBManagerStatePoweredOff, which oddly enough will be the case regardless if bluetooth is turned off from System Settings or if it is toggled off from the Control Center.
If your app works in the background you may want to use a local notification instead to get your user's attention.
Not a perfect solution, but it should be more reliable.
I have filed bug report 47516284 with Apple for this problem. Here's the text of the issue I filed.
I have noticed that the system alert notifying a user that an app needs Bluetooth will show when I turn off Bluetooth using the Settings app. I can use this system alert to go directly to bluetooth settings to turn it back on. However, when I turn off Bluetooth using Control center, there is no system alert that displays. This is problematic because although I can display a custom alert to tell the user to turn on Bluetooth, there is no way to code bringing the user directly to Bluetooth settings by tapping a button for instance. I believe the functionality should be consistent no matter how the user turns off Bluetooth.

how to handle when phone switch off in iOS

I need to get the time when an iPhone switches off due to battery or other reasons. But, I need to save when the phone switches off time and when the phone switches on time using objective-c code. How do I do this?
You cannot detect phone switch off. But what you can do is to add an observer via Notification Center to monitor battery level changes.
UIDeviceBatteryStateDidChangeNotification
You need to create a logic to check current battery level and then save the time stamp.

Delegates not available on BLE Authentication

I am able to read and write data from my iOS app(Central). Just after Delegate connectPeripheral:periphal is called, OS gives an alert asking for authentication PIN with two buttons "Cancel" and "Pair".
I am not able to get any notification when user presses "Cancel" or "Pair" button. I am also not able to detect if the pairing is successful or not.
self.peripheral.state always returns 2 (connected)
I have done some research to handling Cancel event of pairing popup but unfortunately apple doesn't provide any delegate to handle it.

MapView hiding "Allow location services" prompt

The first screen of my app is a MapView so when the user opens it up for the first time it prompts for Location Services. The issue is that immediately after the prompt comes up asking for location access it gets hidden (fades into the background) like some subview came over top of it.
Does anyone have a fix for this?
It sounds like you are either proceeding with another prompt for location services before the confirmation is given, or else you are on iOS 8 and prompting for location services (which is now asynchronous) and then going ahead and using them before this can complete.

Resources