When the baby passes through the birth canal, the pressure forces any fluids (ideally) out of the baby's lungs, then the contact with air, the temperature drop, and other physiological changes trigger the first breath/inspiration. However, the baby is still attached via umbilical cord to the placenta, and is still receiving good oxygenated blood from mom until the placenta detaches, then the pulse of the cord stops (this can take minutes). But yeah, an apneic baby is a very time sensitive emergency.