How can I recognize a tap onto the back of a phone when it is in a pocket on the lockscreen? - ios

I want to be able to recognize a double tap on the phone when it is in the users pocket. I know sleep cycle has a feature like this for snooze. Is this possible to implement while the phone is locked? Can apps still receive accelerometer data when locked? I don't know how else one would code this besides using the accelerometer.

Related

Swift detect power button press event

Is it possible to somehow get a callback when the user presses on the physical power button on iOS? Just to make sure, I am not actually trying to change the behaviour of the power button, I just need to know when it was pressed.
Here is some extra info to explain why I need this callback. Our app uses a guided access mode to lock students in test and although guided access allows locking the device via the power button, that lock, unfortunately, causes our sockets to disconnect so we do not allow that. So what I need now is to detect the power button press so I can implement a fake lock in our app where I will dim the display and show a black image on top to save some battery power.

How can you use a button to send a vibrational pattern to another iOS device in swift?

The user enters another user's phone number. If both people are inside the app simultaneously, each user can tap a big button which makes the other person's device vibrate simultaneously. How can I make the button make the other person's iOS device vibrate?
You need to establish some line of communication between the two devices. This is a very vague question, in general, but to get immediate vibration, you'll want some server communicating over a socket with both devices. If one device presses the button, it tells the server to vibrate the other device. The server then tells the other device to vibrate.

how to handle when phone switch off in iOS

I need to get the time when an iPhone switches off due to battery or other reasons. But, I need to save when the phone switches off time and when the phone switches on time using objective-c code. How do I do this?
You cannot detect phone switch off. But what you can do is to add an observer via Notification Center to monitor battery level changes.
UIDeviceBatteryStateDidChangeNotification
You need to create a logic to check current battery level and then save the time stamp.

How to create iPhone app without user operation in response to the iBeacon detection

Is it possible the following behaviors on my iPhone app ?
1) Proccess begins in background ,when detecting iBeacon wave.
2) Proccess begins with a screen, when detecting iBeacon wave, but
the application will finish automatically(without any user operations) after proseccing.
To simply put it, no. In order for your code to execute in the first place, the user needs to tap on the app. That sort of style application MAY be able to work on Android, but not on iPhone.
You CANNOT start an application from the background.
Also, when it's in the background, you CANNOT bring its UI up and obstruct what the user's trying to do.

Detecting continuous/repeated shaking

An app I'm writing requires the user to shake their device for X seconds.
I tried doing this via motionBegan and it works sometimes. But sometimes either motionEnded or motionCancelled get called in the middle of the shake process, and motionBegan doesn't get called again unless you stop shaking completely. And there doesn't seem to be a way to detect whether the device is currently shaking.
There are a number of apps in the App Store that do this successfully, so there's obviously something I'm missing.
Motion events are discrete: Once iOS detects the device has been shaken, it sends the corresponding event and that's that—you have no way to tell it you're interested in long or short shakes. In fact, the documentation here says:
An event is canceled if the shake motion is interrupted or if iOS determines that the motion is not valid after all—for example, if the shaking lasts too long.
If the basic shake motion events aren't adequate for your application, you'll need to implement your own custom shake detection using accelerometer data. This answer is a good place to start.

Resources