Is it safe to view an eclipse on an iPhone camera?

It is safe for your eyes, but not for your camera. The concentration of solar rays on your camera sensor will literally fry it and melt insides of your camera. This applies to all camera devices and not only to an iPhone camera. There are few apps now in the store to take photos of the eclipse. One just needs to fix the exposure and make the phone ready to click on time.

The best way to watch a solar eclipse is to project the image of the sun on a white wall or something.

it is safe to view it through electronic devices with no direct optical path from the lens to your eye.

That includes smartphones, compact and mirror-less camera screens or EVFs.

DO NOT try to do it with SLRs, telescopes or other magnifying optical devices without the use of appropriate dark filters, or the light will be concentrated to your eye through the viewfinders and damage beyond what is possible with naked eyes might occur.

What is bad for your eyes is bad for your camera as well. That includes the camera on iPhone. You should use appropriate filters to prevent damage to your phone lens and sensors, and of course, your eyes.