How does iPhone's compass work? How exactly does iPhone's Compass app work? Is there some kind of chip sensitive to Earth's magnetic field or does it deduce the device's orientation from GPS and other location data? Or a combination of both?

If there are differences among different models of iPhone, of course I'd be interested in learning them. Is the iPhone 7 different in this regard?
The iPhone 5s Compass app reacts to a magnet.  This proves that it uses a magnetic sensor.