Apple last night delivered stronger-than-expected results for its second quarter as gains in services helped offset slumping iPhone sales, sparking a rally in shares of the technology giant. 

California-based Apple reported a 16% drop in profits for the three months to the end of March to $11.6 billion, as overall revenues dipped 5% to $58 billion.

Apple shares rallied 5% in after-hours trade, with the results showing better-than-anticipated results from its new products and services in the fiscal second quarter to March 30.

"Our March quarter results show the continued strength of our installed base of over 1.4 billion active devices, as we set an all-time record for services, and the strong momentum of our wearables, home and accessories category, which set a new March quarter record," Apple's chief executive Tim Cook said. 

"We delivered our strongest iPad growth in six years, and we are as excited as ever about our pipeline of innovative hardware, software and services." 

Apple has been scrambling to develop new revenue streams amid stagnant growth and increased competition in the smartphone market, which has been the company's main profit driver. 

The latest quarterly results showed revenue from iPhone sales slumped 17% to $31 billion. Apple has stopped reporting iPhone unit sales. 

China-based Huawei outsold Apple's iPhones in the first quarter of this year, seizing the US company's second place spot in a tightening smartphone market dominated by Samsung, according to Chinese-owned market tracker IDC. 

A total of 310.8 million smartphones were shipped globally during the first three months of this year in a 6.6% decline from the same time in 2018, preliminary IDC data showed.

It was the sixth consecutive quarter of decline for global smartphone shipments. 

Apple had a challenging first quarter, with iPhone shipments dropping by a "staggering" 30.2% from a year earlier to 36.4 million units, IDC reported. 

Huawei, meanwhile, weighed in with 50.3% growth to ship 59.1 million smartphones and put it within "striking distance" of Samsung, according to IDC. 

South Korean consumer electronics giant Samsung saw smartphone shipments drop 8.1% to 71.9 million in the first quarter. 

But the money Apple took in from services or digital content grew 16% to $11 billion, reflecting growth in music, Apple Pay and other new offerings from the firm.

Apple also saw growth in its wearables - which include its Apple Watch and earbuds - and its smart HomePod speaker. 

The company also said it would spend an additional $75 billion for share repurchases and boost its dividend, delivering more cash to its investors. It ended the quarter with some $225 billion in cash.