How to prevent the CoreBluetooth library from prompting to turn-on an iOS device's bluetooth? - iphone

I would like to detect whether an iOS device has Bluetooth enabled so that I can prevent the CoreBluetooth library from prompting the app user to enable it. I am NOT looking to check the state of the CBCentralManager; I just want to prevent the blue popup box so that it doesn't annoy my users.

You can't use CoreBluetooth in your app without the dialog. So if you want to prevent it all together, you can't.
If you just want to prevent if if they have Bluetooth off, then checking the state of CBCentralManager first is the right approach (ie check to see if it == CBCentralManagerStatePoweredOff).

Related

Executing code of app without opening view for user

I want to execute code on background, when user clicks on app icon? Is it possible? I want to turn bluetooth when I click on app icon on Iphone. Thanks a lot !
As per this answer, there is no way to turn on Bluetooth without Apple rejecting your app. Therefore, the best way to have the user turn on Bluetooth is to tell the user to do so(e.g. through an alert/popup).
As for executing code in the background, check out this answer, which describes how threading works in Swift.

Is it possible to flash a flashlight in iPhone when application is background mode?

Is it possible to flash a flashlight in iPhone when application is background mode?
Please give some suitable suggestion.
Already given the answer similar of your this question, pls see this link at once
Iphone flashlight not working while app is in background
This is a normal behavior.
Apple's sandboxing will not allow you to keep the flash on while your app is in the background.
There is no workaround unless we are talking about a jailbroken app.
Edit:
Apple is very strict on it's system's APIs usage. Especially when it comes to:
- User privacy
- Battery life
- User experience
In the case of the flashlight, the last two items are relevant. Apple will not let an app drain the battery when not in the foreground and iOS users are used to the fact that flashlight, camera, microphone... are immediately disabled when going to the background (with an exception for the microphone in some background modes cases).
To answer the comment on your initial post, iOS controls your hardware. So since Apple decided they don't want the light to stay on when the user closes the app, iOS will just power off the flash when your app goes in the background. Your app has no authority to prevent it.
When in background your application doesn't work or get any messages from the system.
The only cases when this is allowed are:
navigation application
audio player
Internet telephony
Unless you are designing any of the above you can not flash the user with anything.
If you only want to notify the user about something, you can create a notifier that will pop a message in the users window even if your application is in the background or entirely off. the user can click the message and then he will be back to your application
My app is an audio player, so it keeps running in the background. But flashlight works only when it's in the Foreground. No flashlight from the background.
try AVCaptureDevice
AVCaptureDevice

Can I make an app that toggles on and off the iPhone's bluetooth?

I have been looking around for an answer to this, but haven't been able to find anything. Can I toggle on/off my iPhone's bluetooth signal from an app. I hate the process of doing it through the settings app.
I don't have any desire to get this approved through the app store, I just want it for use on my phone (very similar to the Android functionality).
Yes! Jeff Broderick made a handy site that lets you add a shortcut icon to your home screen to do this sort of thing. http://brdrck.me/settings/
I use it for Airplane Mode and Wifi. Haven't tried the Bluetooth, but I'd imagine it works as well as the others.

Find focus in OS X

Is it possible to create an app for the mac (and iphone afterwards) that does something when it detects that the focus is on a certain object in the screen?
Meaning, the program runs in the background, and when it detects that the focus (or cursor) is on an edit box, it will run something.
Hopefully I made myself clear!
Thanks!
You can do this on the mac by using the Accessibility Framework.
Note that users will have to manually enable assistive devices and you will not be able to distribute your app on the Mac App Store due to Apple's soon-to-be-implemented sandboxing restriction.
On iOS, you can detect focus to certain but not all elements using specialized delegate methods such as textViewDidBeginEditing:. That said, as users use taps to navigate iOS apps most of the time, simple tap handling seems like a much better approach.
On the iPhone, you can only detect focus within your own app, there's no way to observe other apps from the background.
On the Mac, as 0x90 noted, the closest you'll get are the Accessibility APIs. The UIElementInspector sample code may help you to get started.

Device auto-lock

I have an application in which I want to lock the iPhone programmatically so that the user can't perform any action.
How can I determine the user is not working with the iPhone for some period, and after that period automatically lock the phone?
Such applications are used in all phone devices, where the user can set an auto-lock time and then the device will automatically lock if the user does not handle the device.
How is it done programmatically? Please give me one example of the code so I can perform this easily.
I am new to iPhone programming, and I am struggling in my application. Help me. Thanks in advance.
(For your lock the iphone device through programatic only )
Impossible.
But , you could prevent your phone from locking when your app is running.
[UIApplication sharedApplication].idleTimerDisabled = YES
There is no way to disable the Home Button in iOS using the documented API. The user will always be able to get back to the home screen or close your application using the Home Button.
Even if you find a way do it (which is very unlikely) your app will be definitely rejected from the App Store for a blatant violation of the iOS Human Interface Guidelines. If I were you I would reconsider implementing this behaviour, frankly, it's just not a good idea.
If you're only looking for blocking the the UI of your app, check out the answers to this question, more specifically, check out the incredibly useful MBProgressHUD library: