The longtime leader of the iPhone maker will be replaced by John Ternus, the company’s head of hardware engineering.