Bluetooth icon stays white? - ios

I am working on an iOS app which uses Core Bluetooth. When the app gets SIGKILL-ed, the Bluetooth icon on one device stays white, even though it isn't connected to anything. When I next run the app, that device has problems connecting to the other device.
How do I "refresh" the connections? Or is there a way to cancel connections before the SIGKILL?
(The devices have to stay connected even when the app is in the background)

As an experiment you can try to retrieve the connected devices with the retrieveConnectedPeripherals method. If the device you are trying to connect is in the connected list, then it may be possible to start using it again.
Also, try to forcefully disconnect the other device by removing the battery or turning it off. If the connection stays there, then this is definitely a bug.
This is most probably an iOS bug or some optimization that is implemented only for handling connections between i* devices. I don't know of others having this issue, neither did I stumbled upon it but in these cases it is best to report it to Apple at the same time with as much info as you can provide (https://bugreport.apple.com/) You should try with newer iOS versions as well to see if it still exists.

Related

Strange bug - Some elements are visible when I run app from Xcode, but not if I start running the app from device

Context: Native iOS app developed with Swift which manages external control units via bluetooth. I use Xcode Version 14.2, but it used to happen with older versions as well. Tested on devices with iOS 15 and 16.
In a specific section what the app has to do is:
take the data through the Bluetooth input and output
go to the outputs screen and present the outputs
from the outputs screen go to the inputs screen and show them
The problem is as follows.
If I take a physical iPhone and connect it to the Mac, then start the app from Xcode, everything works fine.
If, with the same iPhone, I start the app not from Xcode but with a tap from the iPhone screen, the app starts correctly, connects via Bluetooth, shows all the outputs correct, while for the inputs they are all correct except the last. The last one is never displayed, all the others are.
The main problem is that I don't know how to debug since it only happens when the app starts unlinked from Xcode. Does anyone know of other ways to troubleshoot the problem or have had similar problems and know of possible solutions?

(iOS Swift) Some features work on simulator but not on device

I'm making an alarm app. There are two things that work on the simulator but not on my device.
1) According to this website, if UIApplicationExitsOnSuspend is set to "YES", then the app should always be running even if the device is locked (provided that it's in foreground). I used this information to make sure that NSTimer runs even if device is locked. On the simulator, no matter how much time passes by (even like 10+ hours) the NSTimer always works and the sound always fires (even if I lock the simulator screen). When I connect my iPhone device to the computer and run the app through xcode it works well too. But the problem is that as soon as I disconnect my phone and load the saved app, sometimes the NSTimer works and sometimes it doesn't.
2) Local Notifications: On the simulator the local notifications work well but on the iPhone device the notifications are fired at random times and sometimes they don't even fire. But on the simulator the local notifications fire accurately. I tested in different ways (such as setting local notification to fire 20 seconds after app loads and then exiting the app to be in background mode) but it doesn't fire on the specified time and like I said it sometimes doesn't even fire.
In such case, should I trust simulator or the iPhone device? Could this be a bug or is it something I'm doing wrong?
Always trust the device. After all, that's how the end user is going to run your app!
It is well known that you should not trust the Simulator for background behavior. The NSTimer issue is an excellent example. The problem is that the Simulator is your computer, not an iOS device. Timers do not in fact run in the background; the Simulator is misleading you. (The issue where the app behaves differently on the device if being run from Xcode vs. being run independently is a bit more suprising, but in this case I suppose it isn't all that surprising; you were very clever to think of testing both ways.)
And of course there are lots of iOS features that don't work on the Simulator at all.
I figured out the problem for #2. I simply canceled previous notifications before firing new ones.
I'm still facing issues with the first problem.

Xamarin - iOS backgrounding with BT low Energy and TTS

I'm working on a proof of concept app. I'm using Xamarin for iOS. The iPhone app runs in the background and watches for particular BTLE devices and speaks using TTS when the signal is at a certain strength. I have TTS working and I can recognize the BTLE devices when the app is in the foreground.
However, I'm having trouble getting either working when the iPhone screen is off. In Android, I'd just use a wake lock, but that appears to not be available in iOS. I tried setting the background modes in the info.plist file for BTLE and sound, but I don't see any processing happen while the unit is suspended. Can anyone point me in the right direction?
This is just a proof of concept, so I'm only looking at the latest iOS version and I'm interested in even hacky answers.
Thanks!
You will need to create at least one background task UIApplication.SharedApplication.BeginBackgroundTask and end it with EndBackgroundTask when you finish transferring your data.
Note that you will have approximately 10 minutes in background. If user switch back to the app the time will be reset.
You might also want to disable application idle timer to prevent the screen to go black when the user doesnt touch it.

canDisplayBannerAds and Airplane Mode

I'm testing my app in the Sandbox, and I'm using canDisplayBannerAds with iOS7. I had this working acceptably until I did some tests where I started the app in Airplane Mode (important to me because I need to detect if there is a network connection and if the user has paid to remove ads). With the iPad in Airplane Mode, I launch the app. Of course, no ads are displayed. Then, I switch to Settings (I don't explicitly quit the app), turn Airplane Mode off (the network is available again), but ads don't come back. Even if I set canDisplayBannerAds to YES again, it doesn't appear to help. The network is available, canDisplayBannerAds is YES, but no ads appear. Thoughts?
Ads won't appear in a number of circumstances, and I'm guessing this is one of them.
The real question you need to ask is
1.) How many users are going to find this out?
and
2.) Who has the time or effort to do this Airplane-mode-toggle-dance for your app. Apps are ephemeral experiences for the most part.

How to programmatically wake an external screen attached to an iPad

I'm developing a standalone kiosk that is composed of an iPad 2, and an external screen. I have the two connected by cable, and the iPad is locked in a special case to prevent it from disappearing. This case makes the access to the connector impossible.
The problem I have is that when the iPad wakes from sleep (user interaction) the screen often doesn't wake up. Once the screen awake however, there is never a problem of it going to sleep by itself (this rules out a physical connection problem). I manage to wake up screen after several tries of switching on/off the monitor or letting the ipad fall a sleep and then waking it up.
My guess is that the iPad fails to send the signal while the monitor is scanning for it. However, after several tries I get them both to do their things at the right time, and that is when it all starts to work.
Hence the question. Can I programmatically make the ipad scan (send signal to) the external monitor? Ideally I would do it from the app I'm developing, but a standalone app could solve a trick too.
I've looked through the UIScreen Class reference and googled quite a bit, but so far to no avail.

Resources