Basically, they use a powerful, waterproof glue to seal the phone against water.
The tricky bit has always been the speakers and charging ports – places where you need to let sound and electricity through, but not water. For these places, they put a special membrane over the hole that allows only what is supposed to get in to go through, and not water.
Latest Answers