Apple reported earnings for its June quarter on Tuesday that were above expectations, and the company's revenue returned to growth after two straight down quarters.
The stock rose more than 4% in after-hours trading.
Apple's guidance was strong and beat analyst expectations, suggesting that demand for Apple products is stabilizing headed into the critical second half of the year. Apple also declared a cash dividend of $0.77 per share.
Here's how the company did versus what analysts were expecting:
"We're very excited to report a return to growth for the quarter, and it's a record revenue for Q3 as well, best we've ever had," Apple CEO Tim Cook told CNBC's Josh Lipton.
Apple's revenue was up 1% from the year-ago quarter. Earnings per share were down 7%.
"Great services quarter, unbelievable wearables quarter, significant progress on iPhone, and off-the-charts significant progress on China, compared to where we were the previous quarter," Cook continued.
Apple said that it had spent over $17 billion on share buybacks of almost 88 million Apple shares, and had also paid out $3.6 billion in dividends and equivalents during the quarter.
"The highlight of this release and focus of investors in our opinion will be the robust September guidance for total revenue of between $61 billion and $64 billion vs. the Street's $60.9 billion estimate," Wedbush analyst Dan Ives said in a note.
Apple's iPhone revenue was lower than what analysts expected, and fell 12% from the same quarter last year. Weakness in Apple's flagship product was partially offset by strength in the Mac and Wearables divisions.
The iPhone accounted for 48.3% of Apple's overall revenue, the first time that it hasn't contributed over half of Apple's sales since 2012.
Apple's wearables business includes Apple Watch, AirPods, and Beats headphones. In a statement, Apple CFO Luca Maestri said the product category was "accelerating" with growth over 50%.
Services revenue, which includes subscriptions, App Store fees, and other online services, grew by 13%, slightly under analyst expectations. Apple CEO Tim Cook told CNBC that after factoring out payments from a lawsuit and taking foreign-exchange rates into account, that its services product category would have grown by 18%.
Services margins were over 64%, contributing to Apple's bottom line. The total services sales were an all-time record, Cook said on a conference call with analysts.
"Our strong services performance was broad-based," Cook said in a call with analysts. "We set new all-time records for AppleCare, music, cloud services, and our App Store business, and we achieved a new third quarter revenue record for the App Store."
If you add the wearables and services product categories together, they are together approaching the size of a Fortune 50 company, Cook said, underscoring that Apple's non-iPhone product lines are still massive, even if they are not as big as the iPhone.
The installed base of iPhones hit an all-time high, Apple said, although it did not provide an updated number. In January, Apple said that there were 900 million iPhones in use.
Apple also outperformed expectations in China, which had been one of the main factors in disappointing quarters earlier this year. Cook said in an interview with CNBC that a Chinese VAT tax cut had been a big help, and that he saw no signs of a nationalistic boycott of Apple products in China.
"The VAT reduced from 16% to 13%, that's clearly a big help. We took some price action, that's a big help. We introduced trade-in and financing, that's a big help. The more subjective thing is, when the countries are meeting and talking, that's better than not," Cook told CNBC.
Apple said that it had $9.61 billion in sales in its Greater China category, which also includes Taiwan and Hong Kong. In the previous quarter, Apple's Greater China sales declined 22%, China sales were only down 4%. Cook said that Apple returned to growth in mainland China.
Apple bought Intel's modem division earlier this month for $1 billion, an unusually large buy for the company.
"This is our second largest acquisition by dollars and our largest ever in terms of staff," Cook said.
Modems are semiconductor components used to connect to cellular networks like those run by Verizon and AT&T. Earlier this year, Apple settled a long-standing legal dispute with Qualcomm and signed a deal to buy smartphone components, including modems, from Qualcomm for several years; Apple had previously been working with Intel to try and replace Qualcomm as a supplier.
Cook explained the purchase was strategic, and that Apple has a long-term strategy of "owning and controlling the primary technologies behind the products that we make."