How I Built an iPhone Theft Detection System Using Motion Sensors and Screen Time APIs

https://hackernoon.imgix.net/images/UU8y4gctGFRwo3WzEWXQHbaThNZ2-m3939pj.jpeg

Phone theft is a major issue nowadays. According to the police statistics, 117,000 phones were stolen in London alone in 2024. The same year, Rio de Janeiro had 58,820 such cases.

Android has had Theft Detection Lock since 2024 – it uses ML to detect when your phone is grabbed and snatched. Apple has nothing equivalent. So I built one.

Here's what I learned about accelerometers, Screen Time API, and keeping background processes alive on iOS, while building my first Swift project.


The detection algorithm

The core is pretty straightforward:

motionManager.accelerometerUpdateInterval = 0.05 // 20 HzmotionManager.startAccelerometerUpdates(to: .main) { data, error in guard let data = data else { return } let x = data.acceleration.x let y = data.acceleration.y let z = data.acceleration.z let magnitude = sqrt(x * x + y * y + z * z) if magnitude > threshold { onSnatchDetected(magnitude) }}

This is it – just...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE