Chinese regulators have been penalizing overseas companies, like the American mobile chip giant Qualcomm, which was forced to reduce prices for companies that sell smartphones within the country. It is a market increasingly dominated by Chinese brands like Huawei and Xiaomi that undercut Apple and Samsung on price.

China is also scrutinizing Western technology companies over national security issues. Beijing has increased oversight of the internet with new cybersecurity rules and forced state companies to reduce spending on overseas technology. It pressed Apple to hand over its source code. Apple said it refused.

Apple has agreed to the government’s request to store more of its local data on Chinese servers. It must also undergo “security audits” on new models of the iPhone before gaining approval to sell the product.

Beijing also expects American companies to help develop China’s own capabilities. Apple is teaming up with UnionPay, a state-backed financial services company. It has invested $1 billion in the Chinese ride-hailing service Didi Chuxing, which has significant backing from state companies.

Mr. Cook, Apple’s chief executive, has also carefully cultivated Apple’s image as a big employer, a good corporate citizen and a major economic contributor. He comes to China regularly. He has donned factory uniforms and walked the assembly line in Zhengzhou. He has courted regulators, the heads of state telecom giants and the country’s top leaders, including Mr. Xi.

In an interview with Chinese state television last year, Mr. Cook explained how Apple was planting trees in the country, calling the effort a “pillar of its environmental strategy.” He detailed plans to build a massive solar project to power Apple’s stores, headquarters and offices throughout the country. He also boasted about creating over three million jobs in China, half of them in manufacturing.

At the Hall of Purple Light in the government’s walled leadership compound in Beijing, Mr. Cook promised in August to build the company’s first research and development center in the country and to support the government’s big focus on high-end manufacturing.

Opposite him sat the vice premier, Zhang Gaoli. Beside him sat his partner. There was the chairman of Foxconn, Mr. Gou. Also present was the party leader of the province where Zhengzhou is located, Xie Fuzhan.