iPhone 4s not receiving iBeacon notifications in background - ios

iPhone 4s not receiving iBeacon notifications in background.
I have an app that acts as an iBeacon and also scans for them.Using an iPhone 5, iPad Air, and iPad mini Retina I get the notifications in the foreground and background.
One of our testers has a 4s and apparently only gets notifications in the foreground. It can apparently take up to 15 minutes to deliver the notification and apparently it is not arriving in that time frame. For background modes I have location updates, external accessory communication, uses bluetooth LE accessories and acts as bluetooth le accessory.
I also have notifyEntryStateOnDisplay set to YES. What is weird is that it does work as expected on all devices so I am curious if anyone else has seen this issue.
Currently I am confirming that:
a) It is for sure a 4s.
b) That background use is on for that app.
c) Will get a 4s tomorrow to try hands on.

This is really tricky to test, so I would try it yourself and not rely on reports of a "tester". When you get your 4s, if you do not see background notifications in 15 min of an iBeacon showing up, try hitting the shoulder button and verifying you get it right away.
If this does not help, I'd suggest:
Post your code that produces this problem so others can try.
Try to run the code in the github project referenced in my blog post here and see if that code triggers within 15 min.
If the code in (2) works, there might be an issue in how you are setting it up.

Related

Beacon based app suggestion on lock screen not shown in iOS 10

My app uses background beacon scanning. I have written locationManager.requestAlwaysAuthorization() and locationManager.startMonitoring(for: region) in my code. When I open the beacon, the lock screen of my iPad mini (iOS 9.3) shows my APP's icon. However, it's not shown on the lock screen of my iPhone 5s (iOS 10.3).
I have checked the didDetermineState, didEnterRegion, didExitRegion callbacks. All of them works fine on both devices.
Is it a bug or should I do some additional settings to make my APP appear on the lock screen suggestion in iOS 10 device?
The feature that shows a suggested app icon on the lock screen based on a CoreLocation region entry event seems to have been removed from iOS 10, although there are inconsistent reports, and some users with early version of iOS 10 insist they still saw it happening. In iOS 8-10, there is still a separate Handoff feature that often shows Safari icons on the lock screen, that may be confused with suggested apps.
In my tests, the same BeaconWizard app that monitors for a single CLBeaconRegion has its icon appear on the lock screen when the beacon is turned on in iOS 8.3.
It does not show up on the lock screen in iOS 10.1.1.
In iOS 10, a similar Siri suggested apps feature appears if you swipe right on the lock screen. It is unclear what algorithm is used for the suggestions. Location may be one factor, but I am not able to get apps to consistently appear in this list based on location events.

Core Bluetooth scan for peripherals while the phone's screen is off

I need to keep scanning for broadcasts from peripherals while the app is in background and when the phone's screen is off. Scanning from background was successful but I can't scan (can't trigger didDiscoverPeripheral) broadcasts when the phone' screen is off.
So far I've implemented beginBackgroundTaskWithExpirationHandler inside applicationDidEnterBackground and that's how I am able to scan in background. So how should I do this?
This is not possible.
When you tick 'Uses Bluetooth LE accessories' and 'Acts as a Bluetooth LE accessory', when iPhone screen light is turned off, core bluetooth framework stops advertising and scanning. It resumes advertising/scanning once the screen light turns back on. That's the maximum possible achievable scenario in iOS.
If you want to take this further, you can use beginBackgroundTaskWithExpirationHandler - https://developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiratio but that works hardly for 3 minutes. Those 3 minutes start as soon as the app goes from foreground to background.
For saving battery, iOS seems to automatically turn off the BLE hardware and it goes back on as soon as the device moves/screen wakes up. Because when screen is off, user isn't using the iPhone anyway.
Edit: Unless a device is connected, like a headphone- Though not advertising, existing connected devices can share data.

(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.

Total screen unlock time calculation in iOS

For my current project, I need to calculate the total time while an iOS device is unlocked i.e. the user is working on his device. I am aware of the Darwin Notifications as available in CFNotificationCenter as specified in this Stackoverflow question. I have tested this code on my iPhone 5C. It is woking fine for foreground mode. But I am not able to receive those notification when the application is in background mode. Is it possible to receive those notification in background mode? Or is there any other way to calculate total unlocked time for a device from my app even when the application is in background mode?
As explained here. Background mode can only be used for specific purposes. If your App is not using background mode for any of those purposes (which it isn't), it will not work.
In short, it could only work on a jailbroken device.

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.

Resources