SAN FRANCISCO — Apple’s chief executive, Timothy D. Cook, may be the leader of the world’s most valuable public company, but lately he has had to act a lot like the tech industry’s top diplomat.

Last month he visited the Oval Office to warn President Trump that tough talk on China could threaten Apple’s position in the country. In March, at a major summit meeting in Beijing, he called for “calmer heads” to prevail between the world’s two most powerful countries.

In a trade and technology showdown between the United States and China, Apple and Mr. Cook have a lot to lose. With 41 stores and hundreds of millions of iPhones sold in the country, there is arguably no American company in China as successful, as high-profile and with as big a target on its back.

Since he took over Apple from its co-founder Steve Jobs, in 2011, questions about whether Mr. Cook, 57, could recreate the magic that led to the iPod and iPhone have persisted. For Mr. Cook, the analogous breakthrough — and potentially his legacy as the heir to Mr. Jobs — has come not from a gadget, but from a geography: China.