Tim Cook built Apple into a $4 trillion company. Now, John Ternus takes over, facing an unfinished challenge in AI.