July 23, 2013  -- Apple Inc. (NASDAQ: AAPL) reported that it sold 31.2 million iPhones for the three months ending in June, better than Wall Street's expectation amid a competitive smart phone market. CEO Tim Cook promised "amazing new products that we will introduce in the fall and across 2014."

Brian Colello, analyst with Morningstar, said the "strong" iPhone sales contributed to the company's quarterly earnings of $6.9 billion and revenue of $35.4 billion, which were slightly better than expected, though earnings were still down from a year ago. Revenue is essentially flat compared to the same period a year ago.

In after-hours trading, the stock rose about 5 percent to $440 a share.

Colello said the biggest boost to Apple's stock may be its "massive" $16 billion stock buyback this quarter.

"Apple's been an aggressive buyer of the stock as it has hung around the $400 price range," he said.

At the close of New York financial markets on Tuesday, the stock was trading at $418.99, down 1.72 percent. Apple's stock has fallen about 20 percent so far this year.

"We are especially proud of our record June quarter iPhone sales of over 31 million and the strong growth in revenue from iTunes, Software and Services," said Apple CEO Tim Cook in a statement. "We are really excited about the upcoming releases of iOS 7 and OS X Mavericks, and we are laser-focused and working hard on some amazing new products that we will introduce in the fall and across 2014."

Apple's CFO Peter Oppenheimer said in a statement, "We generated $7.8 billion in cash flow from operations during the quarter and are pleased to have returned $18.8 billion in cash to shareholders through dividends and share repurchases."

Colello said he was most interested in iPhone unit sales and Apple's overall gross margins, which he expected to be affected by iPhone prices, and the mix of sales between the iPhone 5 and the older cheaper 4 and 4S models. Colello expected a decline in iPhone prices, which fell 5 percent sequentially, because prices tend to fall as products age.

The Cupertino-based tech company said it sold 31.2 million iPhones, a company record for the June quarter, compared to 26 million a year ago in the same period. Many analysts expected Apple to sell about 27 million iPhones in the quarter that ended June 30.

The company sold 14.6 million iPads compared to 17 million a year ago. It sold 3.8 million Macs, compared to 4 million a year ago.

In April, Apple reported better-than-expected earnings in its second quarter, saying it sold 37.4 million iPhones and 19.5 million iPads, but its guidance for the following quarter disappointed most investors.

Since its introduction in June 2007, the iPhone has typically been the company's biggest money maker. Sales of the iPhone comprised 51 percent of revenue in the three months that ended in June.

The company said it expected revenue between $34 to $37 billion in the next three months, in line with many analysts' expectations.

Colello said, "Apple's forecast for Q4 appears light, but gross margins are expected to hold up well."

Read More About Apple Reportedly Testing iPad and iPhones With Bigger Screens

On Monday, Reuters reported Apple has been testing an iPhone screen larger than 4 inches and an iPad screen slightly smaller than 13 inches with its Asia suppliers. The current iPhone 5 has a 4-inch screen and the iPad has a 9.7-inch display.

ABC News' Joanna Stern contributed to this report.