SAN FRANCISCO — In the run-up to President Donald Trump’s recent trip to the Middle East, the White House encouraged CEOs and representatives of many U.S. companies to join him. Tim Cook, Apple’s chief executive, declined, said two people familiar with the decision.

The choice appeared to irritate Trump. As he hopscotched from Saudi Arabia to the United Arab Emirates, Trump took a number of shots at Cook.

During his speech in Riyadh, Saudi Arabia, Trump paused to praise Jensen Huang, CEO of Nvidia, for traveling to the Middle East along with the White House delegation. Then he knocked Cook.

“I mean, Tim Cook isn’t here, but you are,” Trump said to Huang at an event attended by CEOs such as Larry Fink of asset manager BlackRock, Sam Altman of OpenAI, Jane Fraser of Citigroup and Lisa Su of semiconductor company AMD.

Later in Qatar, Trump said he “had a little problem with Tim Cook.” The president praised Apple’s investment in the United States, then said he had told Cook, “But now I hear you’re building all over India. I don’t want you building in India.”

On Friday morning, Trump caught much of his own administration and Apple’s leadership off guard with a social media post threatening tariffs of 25% on iPhones made anywhere except the United States. The post thrust Apple back into the administration’s crosshairs a little more than a month after Cook had lobbied and won an exemption from a 145% tariff on iPhones assembled in China and sold in the United States.

The new tariff threat is a reversal of fortune for Cook. In eight years, he’s gone from one of Trump’s most beloved CEOs — whom the president mistakenly and humorously called Tim Apple in 2019 — to one of the White House’s biggest corporate targets. The breakdown has been enough to make insiders across Washington and Silicon Valley wonder: Has tech’s leading Trump whisperer lost his voice?

Nu Wexler, principal at Four Corners Public Affairs and a former Washington policy communications executive at Google and Facebook, said Cook’s “very public relationship” with Trump has backfired.

“It has put Apple at a disadvantage because every move, including a potential concession from Trump, is scrutinized,” Wexler said. Because Trump didn’t “have much incentive to either go easy on Apple or cut a deal on tariffs,” he said, “the incentive to crack down is much stronger.”

Apple did not provide comment. The White House declined to comment on the Middle East trip.

Trump’s new tariff threat followed a report by The Financial Times that Apple’s supplier Foxconn would spend $1.5 billion on a plant in India for iPhones. The president said the tariffs would begin at the end of June and affect all smartphones made abroad, including Samsung’s devices.

Last week, Cook had visited Washington for a meeting with Treasury Secretary Scott Bessent. During an appearance on Fox News on Friday, Bessent said the administration considered overseas production of semiconductors and electronics components “one of our greatest vulnerabilities,” which Apple could help address.

“President Trump has been consistently clear about the need to reshore manufacturing that is critical to our national and economic security, including for semiconductors and semiconductor products,” said Kush Desai, a White House spokesperson. He added that the administration “continues to have a productive relationship with Apple.”

The timing of the White House’s new tariff plan couldn’t be worse for Cook, who has led Apple for nearly 14 years.

Last month, the company suffered a stinging defeat in an App Store trial. The judge in the trial rebuked Apple executives, saying they had “outright lied under oath” and that “Cook chose poorly,” and ruled that Apple had to change how it operates the App Store. Jony Ive, Apple’s former chief designer who became estranged from Cook and left the company in 2019, joined OpenAI last week to build an iPhone competitor. Its Vision Pro mixed reality headset, released in January 2024 to fanfare, has been a disappointment. And in March, Apple postponed its promised release of a new Siri, raising fresh doubts about its ability to compete in the industry’s race to adopt artificial intelligence.

Still, Apple’s market value has increased by more than $2.5 trillion under his leadership, or about $505 million a day since 2011. And Apple remains a moneymaking machine, generating an annual profit of nearly $100 billion.