How to determine number of locks and unlocks of iPhone programmatically - ios

is it possible to determine how many times my iPhone has been locked and unlocked programmatically when app is foreground and background as well. Code snippet will help a lot...

There's no way to get this information from your App.
You can only know when your app goes to foreground/background via your App Delegate, but not what the user does outside of your App.

Related

iOS - Show View when phone is locked

I'm building an ios app with an alarm feature. I would like to show a view when phone is locked. I want to look exactly like on iOS alarm. If you're an iPhone user try to alarm and locked your phone you will get what i'm talking about. Is it possible? If possible how?
Thanks in advance.
iOS doesn't provide apps that kind of access to the lock screen (or any screen not in your app), so it's impossible to make it exactly like the iOS native alarm. The closest you can get is sending notifications to simulate an alarm, which are visible on the lock screen

Launch app using shake gesture

Is there a way to launch an app by shaking the iPhone?
I want my app to launch when the user shakes their iPhone (a certain number of shakes).
I believe thats not possible.
Apple can deal with this on its own end by OS.
What if the device gets shaken by accident? You've then got false alarms to deal with.

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.

Launch app from background service

I've developed Android app which has a background service in the sleep mode. This service works with accelerometer data and can launch the app from the sleep mode over the lock screen.
Is it possible to make the same on iOS?
I mean:
Create a service which can work in background with accelerometer data.
Service can launch the app when the phone is in the sleep mode over lock screen. (without unlocking)
If I'm not mistaken it must be possible on iOS7, isn't it?
Thanks!
Yes – Apple publicly stated background processing at WWDC keynote and it can be done to a degree on iOS6
No – Apple will 'probably' never allow an app to be opened without the user instigating it and certainly not over the lock screen.
You could use Push / Local Notifications which do appear on the lock screen to try and entice a user at a specific time to launch the app but no guarantees.

Resources