SAN FRANCISCO — Apple exceeded Wall Street’s expectations for revenue and profits for its most recent quarter, as strong sales of Macs and digital services offset flat sales of iPhones while consumers wait for new models to be released in the fall.

The strong results eased Wall Street’s fears that consumers were pulling back from Apple’s products, particularly its flagship, the iPhone.

Apple said little about the upcoming phones and declined to address reports of production delays with a new high-end model, which is expected to feature an edge-to-edge screen and is expected to cost more than $1,000. The company’s revenue projections for the quarter ending in September spanned a wide range, suggesting that executives are hedging on the exact timing of the iPhone update.

“We would obviously rather not remove the apps, but like we do in other countries, we follow the law wherever we do business,” Mr. Cook said during a conference call with analysts to discuss the results. “That doesn’t mean that we don’t state our point of view in the appropriate way.”

He also said that Apple fought the United States government last year over unlocking an iPhone belonging to a dead terrorist because the legal circumstances were different.

“The law in the U.S. supported us,” Mr. Cook said. “It was very clear. In the case of China, the law is very clear there. Like we would if the U.S. changed the law here, we have to abide by them in both cases.”

For the quarter ending July 1, Apple reported revenue of $45.4 billion, up 7 percent from the same quarter last year. Net income was $8.7 billion, or $1.67 a share. Analysts had expected Apple to report revenue of $44.9 billion and net income of $8.2 billion, or $1.57 a share, according to estimates compiled by S&P Capital IQ.

For the same quarter last year, Apple reported revenue of $42.36 billion and net income of $7.8 billion, or $1.42 a share.

The company’s stock rose 6 percent in after-hours trading once the quarterly numbers were released.

In an interview, Apple’s chief financial officer, Luca Maestri, said the company saw increases in unit sales and revenue in every product category, including iPads, which had been struggling in recent quarters. Global sales of iPhones rose 2 percent to 41 million units. Revenue from services, which include app sales as well as iCloud storage and Apple Music, grew 22 percent, ahead of Apple’s previous projections.

Apple said revenue fell 10 percent in greater China, a key market where sales have dropped for six consecutive quarters. But Mr. Maestri said that sales in mainland China had stopped falling, with poor sales in Hong Kong dragging down the region’s numbers. “We feel we will do better in the September quarter,” he said.

The company is wrestling with increased competition in China from Samsung, as well as from Chinese companies making Android phones.

Toni Sacconaghi, an analyst with Bernstein Research, said Apple’s business in China still faces big challenges. The rise of WeChat, a wildly popular Chinese chat app and social network, has made the underlying choice of phone less important to Chinese buyers. And many Android models sport cutting-edge features, yet cost less than an iPhone.

“The jury is still out on China,” Mr. Sacconaghi said.

Apple is also sensitive to the fact that its products are almost entirely made in China at a time when President Trump is pushing companies to increase American manufacturing jobs.

Mr. Trump said last week that Mr. Cook had promised to build “three big plants” in the United States. Asked Tuesday about Mr. Trump’s remarks, Mr. Cook deflected the question, saying that Apple had created two million jobs in America — mostly developers who had written apps for the company’s products and suppliers who made parts that went into Apple products.

However, he added that Apple would have more news coming later this year about its direct employment in the United States. The company’s Mac Pro computers are assembled in Texas, and the aging lineup is due for a revamp, offering Apple a chance to rethink its manufacturing.

A version of this article appears in print on , on Page B2 of the New York edition with the headline: Apple’s Revenue and Profits Rise Even as Buyers Wait for New iPhones. Order Reprints | Today’s Paper | Subscribe

Interested in All Things Tech?

The Bits newsletter will keep you updated on the latest from Silicon Valley and the technology industry.