Hardware is nothing without software.
They make more desirable phones because they make iOS.
People don't so much care about the iPhone; they want iOS and the safety, convenience, and integration with the Apple software ecosystem.
Apple has leveraged this into a hugely profitable position by making the only hardware supported by this OS.
The iPhone is crap when evaluated on battery life or camera quality, for example.
It's software that's eating the world.