iOS app with iBeacon must restart device - restart

I built a simple ios app with IBeacon . I ran this app on an iPhone 4s whit ios7.1 while running an IBeacon base station.Everything is working right in background or foreground(exit region have 30 seconds delay in background).But over a period of time,about 3 hours,this app can not monitor any event though device setting were not change(blueTooth and locate is normal).This situation must restart the device.
Please tell me what should i do aboult this situation?
Thanks!

I wonder if iOS Bluetooth scanning is slowing down when your app is in the background such that it appears that events never fire because they are just taking so long to happen. Rebooting may speed up the cycle.
One way to force a Bluetooth LE scan cycle to look for iBeacons is to run a different app in the foreground that uses the CoreLocation iBeacon ranging APIs.
Try installing Locate for iBeacon, then as soon as your app appears to be not getting notifications in the basckground, launch Locate for iBeacon and tap Locate iBeacons. Do you see iBeacons? Does your background app get a notification?
If this works, then repeat the test and instead of using the Locate app to force a scan, just wait (an hour if needed). See if you eventually get your notification anyway, and note how long it took.
Edit: it appears that this is a case where iOS stops looking for iBeacons entirely requiring a reboot. See related question below.
iBeacon: didRangeBeacons stops getting called, must reset device for it to work again

Related

Fetch Data from BLE Device every 15 min using core bluetooth in iOS

I have specific requirement where i want to fetch data from the connected Ble Device every 15 mins for a period of time like form 10:00 PM to 10:00 AM. Can it be done when my app is in background and device is locked. Obviously, user won't keep the app in foreground for so long. Any suggestions on how to achieve this.
It may be achieved but unfortunately you need to solve this from device perspective.
Your device will need to wake up and initiate connection with your phone whenever you need to sync data. It will wake up your application and even launch it if it was terminated. You can then initiate a standard background process for which you have limited time to do whatever needs to be done. When complete you should disconnect from your device and wait for the process to be repeated.
There might be some hacks like using silent push notifications to wake up your app and try to connect but Apple will most likely not allow this plus there is a great chance your BT will simply not work in that state. Still it is something to try if you really need it.
You have the problem that you can't have a timer in an iOS app. Therefore you have some options that require specific behaviour of the peripheral.
One option is to let the app first connect, and always upon disconnect, it tries to reconnect. Then simply make the peripheral don't advertise for 15 minutes. As soon as it advertises again your app will be woken up because it connected. You can then fetch your data.
Another option is to be constantly connected and have a timer in the peripheral that notifies data every 15 minutes.
Both options requires you to have background capabilities enabled in your app and State Preservation and Restoration.
In background mode(app was killed) iOS device cant communicate with BLE.
Only scan BLE device which have service uuid.
Only background scanning is possible in iOS.
So u can get notification while peripheral was found in Background mode.

How to run ios application in background on device restart?

I am working on Location Tracking Application. This application continuously send location even in background. I am using SLC property.
I am also using silent push trick for location tracking. Logic of Silent push:
Check AppIconbadge number and perform the action according to AppIconbadge number. I have a timer which check AppIconbadge at every 10 seconds.
Now this is the case:
Device is on SLC and put the app in background and turn off the device. While you switch back to On this device it is still reporting on SLC while Ping (Silent Push) is not working.
I have started the timer when app get SLC trigger. But its not working.
Can you help?
You can't do it.
The way iOS achieves great battery life and reduces RAM usage makes this kind of thing impossible.
Your only real possibility is to have your server send occasional push notifications to the device, and have your app on the device respond with its location. This is how Find My Phone and Find My Friends both work. The idea is to improve battery life by doing as much as possible on a server, which has mains power and virtually unlimited RAM, instead of on the phone which only has a battery and might need all it's RAM to play a 3D game
Basically the CPU is not running at all most of the time, so it can't schedule stuff to run periodically, and you can't rely on there being enough RAM available to run your app so it also can't be running all the time even if the CPU is powered on.
According to the WWDC 2013 keynote, push notifications are much more powerful on iOS 7, so you should look that up (I haven't looked into it myself, just saw the keynote.

Running location services in the background on an older 3G iphone

I have a location based application that needs to run in the background. I have several iPhones that I am testing on including a older 3G. I register my app to need background location based services and everything works as advertised accept with the older 3G phone. When you press the lock button, it does an applicationWillResignActive: as expected, unfortunately the phone immediately goes into low power mode and that is that. When you have the phone tethered with the USB cable, and then press the lock button, the 3G phone stays alive and correctly reports location changes. When it is disconnected, it goes immediately into low power mode.
The strange thing is that I am pretty sure that it used to work. I want to see if anyone out there has an app running on an older iphone (3G) which registers for location services and is not immediately put into lower power mode when the lock button is pressed. If so, what am I doing wrong.
I followed all the directions, have locations in my Info.plist.
Thanks for your help!
Cheers,
Bryan
I think you are seeing expected behavior.
I noticed on a recent trip with my old 3g the Location Manager appeared to remain active only when the usb supplied power. On usb, unlocking the phone would bring the app up (google maps in this case) immediately with Location Manager active. Without usb, I had to relaunch Location Manager each time I unlocked the phone.
I strongly suspect this is safety/power-saving feature. The Location Manager sucks battery life at a startling rate, especially on older devices. By running the Location Manager continuously while on battery, you could easily flatline a user's phone without their knowledge.
I would be very leery of any design that requires the Location Manager to run continuously in the background. Test it throughly.
You don't want the economic consequences of users deciding that "when I use Bryan's app, my battery mysteriously dies" or the moral consequences of leaving someone in an emergency without a working phone.

Can bluetooth be used with iOS Multitasking?

I'm thinking the answer to this is no, but does anyone know if a Bluetooth connection can be maintained in the background with iOS? I'm thinking I might be able to keep it around with the finite-task background API, but I haven't found anything indicating whether that's true or not. Another option would be to use GPS notifications and just reconnect every time the app gets a location changed notification.
You a right. It's a NO.
But if you use location change notification to wake up your app, you may have a short period of time to use Bluetooth.
I think that the Bluetooth connection should be maintained, but if your bluetooth application is not the foreground application it will not receive any data / commands, when it becomes foreground it will.
It is possible, I use this trick to allow an App to use foreground APIs for iBeacons to allow the app to range even when the App is in the background.
To range for iBeacons it uses a high power API and as so this is restricted to only run when the App is in the foreground and stops all delegates being called once the App enters the background.
By playing a silent audio file and adding the AirPlay capability to your plist it allows your app to run in the background just as it would if it was in the foreground.
I'm not sure if it will work for your case but as iBeacons do use the Core Bluetooth and Core Location frameworks it might just do what you are asking.
http://yifan.lu/2013/12/17/unlimited-backgrounding-on-ios/
Note although this trick has not been patched by Apple in iOS8 beta 5 it is possible they will in an update.
If you're using iBeacons, there are built-in APIs for handling when you enter/exit a beacon region, and you typically get ~5 seconds to range for beacons at that point before the app is put to sleep. Theoretically, you could start a background task w/ expiration handler that might allow you to range for ~30 seconds while backgrounded, but I have not verified this is the case. I do know that the background task can be started when normal CLRegions are entered/exited while in the background, and there is functionally no difference between CLRegions and CLBeaconRegions in terms of region monitoring, so if I had to guess I would say this is more-than-likely possible.

Does the iOS let developers do this?

Let's say the user leaves the phone on the table. (probably on home screen)
A few hours later, he picks it up. And when it does, the iPhone detects the accelerometer, and it rings.
Unfortunately, this is not possible. Once the OS goes to the home screen, applications running in the background have a limited set of options.
Read this article for more information: http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Not through officially accepted means (i.e. you could do it on a jailbroken phone conceivably). Primarily, you can't run in the background for that purpose. If the app was running in the foreground, you can easily detect motion and perform an activity - but if the phone is left for too long a period without activity, it will sleep.
Unfortunately, the accelerometer is not one of the specified keys in the UIBackgroundModes option in your apps info.plist.
auido, location and voip are the only ones available for now.
short answer: YES
The trick is to make sure the app doesn't get backgrounded when the phone goes to sleep. The other elements like detecting changes in the accelerometer and playing a sound are all standard features.
As for the no sleep solution, it has been asked before, basically is you play a music sample the app will continue running, so perhaps a loop of silence continuously played.
Only if you left an app designed for that purpose running in the foreground.
It won't be possible if your app is running in the background.