How does iPhone's compass work?
The iPhone 5s Compass app reacts to a magnet. This proves that it uses a magnetic sensor.
There's a lot of online speculation on this, and some of it is laughable. Disclaimer: I use Apple products, but otherwise have no affiliation and know nothing with certainty. But, I have a very strong hunch that the the iPhone in all versions uses a device called a magnetometer for the compass. ICYI, the compass reading is combined with inertial data generated by accelerometers in the iPhone and GPS data from its receiver (when available) to calculate the phone's position using a technique known as Kalman filtering.