The iPhone app compass altitude sensor works by using the device's barometer to determine changes in atmospheric pressure, which it then uses to calculate changes in altitude. The barometer measures air pressure changes and compares them to a known baseline pressure, which allows it to determine changes in altitude.
However, it's important to note that the accuracy of the altitude reading from an iPhone app compass altitude sensor can be affected by a variety of factors, including weather conditions, atmospheric pressure changes, and the calibration of the sensor itself.
As for your question about how an altimeter works in a pressurized passenger jet, it's true that traditional altimeters rely on changes in atmospheric pressure to determine altitude. However, in a pressurized cabin, the air pressure is artificially maintained at a certain level, so the altimeter would need to be adjusted to compensate for this. Most aircraft have an instrument called a "cabin pressure altimeter" that is calibrated to take into account the pressurized environment and provides an accurate reading of the aircraft's altitude.
[Link Edited by Moderator]