Can an app know when user is driving from iOS 11 Do Not Disturb While Driving feature?

Viewed 2072

In iOS 11 Apple blocks push notifications by giving a notification that you are driving and notifications are blocked.I am curious can we extract that information from iOS and use it in my app?

EDIT: I have already a mechanism with me to detect driving mode but I want to know whether we can access that data or not and want to know what else is there in that data(if that is available).So please dont post links leading to Driving mode detection algos.

2 Answers

Most of the Apps Performing such operations rely on data from Accelerometer. All smartphones now a days, including iOS has builtin Accelerometer sensor in them.

The idea to predict whether a person is driving or not is to infer speed of the user movement from the data provided by this sensor and perform operation based on that.

All SDKs provide functions that can use this data. Hence, it will be available for you also.

There is no public API that manage Do Not Disturb Driving, if you want to know user activity you can use CMMotionActivity:

var automotive: Bool
A Boolean indicating whether the device is in an automobile.

On devices that support motion, you can use a CMMotionActivityManager object to request updates when the current type of motion changes. When a change occurs, the update information is packaged into a CMMotionActivity object and sent to your app.

All push notification are managed by the system, if they are blocked you can not access to their data. Maybe if you need some notification to do something in your app, you can use Silent Push Notification:

Configuring a Silent Notification

The aps dictionary can also contain the content-available property. The content- available property with a value of 1 lets the remote notification act as a silent notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.

For a silent notification, take care to ensure there is no alert, sound, or badge payload in the aps dictionary. If you don’t follow this guidance, the incorrectly-configured notification might be throttled and not delivered to the app in the background, and instead of being silent is displayed to the user

But maybe this kind of notifications are blocked too:

Do Not Disturb While Driving feature and it will basically turn off your phone without actually turning it off, so no notifications of any kind will be able to get through.

Related