Apple - How does the iPhone Auto Focus work?
Autofocus on the iPhone is done via an electrical motor, moving the front lens backward and forward, and software that captures and analyses the image for best sharpness, which usually is the "sweet" spot. Recent versions of iOS probably offload the analysis to the image signal processor available since the Apple A5 chip.