San Francisco (AFP) - Apple said Tuesday that its profit had jumped more than 30 percent to $11.5 billion in the recently ended quarter, besting market expectations despite selling fewer iPhones than analysts projected.

The news boosted shares in the tech giant in after-hours trading, putting it ever closer to a history-making, trillion-dollar market value, even as China's Huawei knocked Apple off second spot in a tightening global smartphone market.

Apple's revenue in the fiscal third quarter soared 17 percent to $53.3 billion from the same period a year earlier on the back of sales of pricier iPhones, online services and wearable devices.

"We're thrilled to report Apple's best June quarter ever, and our fourth consecutive quarter of double-digit revenue growth," chief executive Tim Cook said in the earnings release.

Apple sold 41.3 million iPhones in the quarter that ended June 30, just shy of the 42 million figure anticipated by analysts.

Shares in the Silicon Valley-based technology titan rose 4.03 percent to $197.95 in after-hours trade that followed release of the earnings figures.

"Apple gave the Street and tech investors finally some good news" beating earnings forecasts and predicting the current quarter will be strong, GBH insights head of technology research Daniel Ives said in a note to investors.

To hit the trillion-dollar market value, Apple shares would have to climb about five percent more.

- No fan of tariffs -

Analysts were eager for news about how the company is riding out trade turbulence between the US and China.

President Donald Trump's trade wars include 25 percent US tariffs on $34 billion in Chinese goods, with more on the way, and steep tariffs on steel and aluminum, which provoked Beijing and others to hit back with import duties on US goods.

Cook said that Apple products have not so far been directly affected, and that the company is evaluating the latest Trump move currently in a public comment phase.

"Our view on tariffs is they show up as a tax on the consumer and wind up resulting in lower economic growth; and sometimes can bring about significant risk of unintended consequence," Cook said while fielding questions on an earnings call.

"All of this said, we are optimistic that this will get sorted out. There is an inescapable mutuality with the US and China which serves as a magnet bringing them together: each can only prosper if the other does."

- Paying top dollar -

The company is expected to unveil new iPhone models in the fall, sticking with its practice of releasing upgraded models ahead of the year-end holiday shopping season.

Sales of iPhones in the fiscal third quarter have typically been tame as many fans have historically either bought handsets in prior months or end up waiting for new models in the months to come.

That said, the average selling price of iPhones jumped in the quarter as buyers opted for top-of-the-line X and 8 models, according to Apple.

"If you look at the top of our line together, they are growing very nicely" Cook said.

"IPhone X shows that when you deliver a great innovative product there are enough people out there that would like that and it can be a very good business."

But the good news was slightly tempered after latest figures showed China-based Huawei took the second-place spot from Apple in a tightening global smartphone market during the second quarter of this year.

South Korean consumer electronics titan Samsung remained the top smartphone maker, shipping 71.5 million handsets, but Huawei moved into second position with shipments of 54.2 million, according to IDC Worldwide Quarterly Mobile Phone Tracker.

The 41.3 million iPhones shipped by Apple gave the company 12.1 percent of the global market compared to 20.9 percent for Samsung and 15.8 percent for Huawei.

It was the first time since early 2010 that Apple wasn't in one of the top two spots in the smartphone market, according to IDC.

- Shining despite bruises -

Apple has managed to shine, despite bruises to its image that included being accused of keeping young people addicted to smartphones, slowing performance of older iPhones to motivate upgrades and sidestepping taxes by nestling cash in offshore havens.

Apple has repeatedly highlighted the growing amount of money it is taking in from music, applications, games, subscriptions and services it sells to people using its devices.

Money made from services is seen as an important element of diversification away from having to rely heavily on selling iPhones.

Cook said the number of people using Apple devices is surging, and that promised to keep fueling the strong growth seen at its streaming music, digital wallet, and App Store.

"We couldn't be happier with how things are going given the momentum we are seeing across the board," Cook said.

"We feel great about our current services and are thrilled about our pipeline with some new services as well."