Differentiate between Homescreen click and Lock Screen click

Hey guys,


I have a bluetooth app that connects to a device. What I want to achieve is this: when a user switches apps or goes to the homescreen, I want to disconnect from the bluetooth device but when a user hits the lock screen, I want the bluetooth connection to be maintained.


I am not super familiar with swift and ios dev so any advice would be great.


Is there a way to determine whether a app is backgrounded due to the user going to the homescreen and when a user simply locks the phone?


Thanks in advance.

Some one seems to have found a trick to see the difference. But no guarantee that it works all times, nor in IOS above 7;

h ttps://stackoverflow.com/questions/19452696/detecting-when-app-is-becoming-active-from-lockscreen-vs-other-on-ios7


it is just a hack and I did not test. In fact system makes no difference between the way you enter in background, as explained in documentation.

h ttps://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html#//apple_ref/doc/uid/TP40007072-CH2-SW1

This does not seem to work. It appears to give me the brightness at the time of the lock button being hit.

Is there a way to determine whether a app is backgrounded due to the user going to the homescreen and when a user simply locks the phone?

As you’ve already determined, the answer here is “No.”

What I want to achieve is this: when a user switches apps or goes to the homescreen, I want to disconnect from the bluetooth device but when a user hits the lock screen, I want the bluetooth connection to be maintained.

What’s the rationale behind this? There are various options you could explore here, but it’s hard to make concrete suggestions without knowing more about the context.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

The idea is to disonnect from a bluetooth device when a user uses his phone (navigates away from the app)

Disconnect from bluetooth may cause problem to other apps or capabilities (like connection to the car audio system). So, that should not be possible, AFAIK.

I can currently disconenct from bluetooth upon the app going into the background however there is not way for me to distinguish between switching apps and simply hitting the lock button, unfornately.

The idea is to disonnect from a bluetooth device when a user uses his phone (navigates away from the app)

But that’s just reiterating your original requirements. I’m curious as to why you want to have different behaviour in the two cases.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I apologize for my lack of explanation. I am hesistant to publicly reveal too much information regarding this project.

I appreciate the help however I am not sure I can expand any further.

I am hesistant to publicly reveal too much information regarding this project.

If you want private help with this you can open a DTS tech support incident, although that will probably be handled by one of my colleagues because Bluetooth isn’t really my thing.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Much later - my use case is around a managing a hotspot connection which I use to to control a device. (using NEHotspotConfigurationManager)

When the user launches the app, then I connect to the known hotspot. Obviously that puts up an alert for them to accept.

When the app is minimised (user is switching to another app) - then I want to remove the hotspot configuration so that I return the device to the prior state.

When the device is simply locked, I don't want to remove the configuration because then I'll have to put up another prompt to reconnect as soon as the user unlocks.

any suggestions?

illustration:

  • App Launches -> Prompt user to connect to hotspot
  • Device Locks -> Nothing (it will be normal for them to spend an hour or so in this state)
  • Device Unlocks -> Nothing
  • App Minimised -> Remove hotspot config, return device to initial state

Currently, I have

  • App Launches -> Prompt user to connect to hotspot
  • Device Locks -> Remove hotspot config, return device to initial state
  • Device Unlocks -> Have to prompt the user again to connect
  • App Minimised -> Remove hotspot config, return device to initial state
Differentiate between Homescreen click and Lock Screen click
 
 
Q