Apple Inc. just had a bad quarter, again. The company’s profit fell in the third quarter of this year while sales of its flagship smartphone also slid during the period. Even worse, Apple is forecasting another decline in revenue next quarter. Yet, the Cupertino, California-based tech giant’s stock rose on the earnings report, indicating that investors are looking at the latest earnings results in a way which is soothing their concerns about the company’s growth.

The world’s largest company by market value said it sold 40.4 million iPhones in the three-month period ended June, down from 47.5 million units a year earlier. The latest slump in unit sales also followed a decline in March, which broke the company’s eight-year run of growing iPhone sales. However, the third quarter’s figure slightly beat the average analyst forecast of 40 million iPhones, according to research firm FactSet.

“There are a number of encouraging signs in the results,” Apple CEO Tim Cook told The Wall Street Journal in an interview, adding that the demand for iPhones was better than what the sales figures showed. “This last quarter was surprising because it was better than we expected from so many different points of view, not just one thing.”

What overshadowed a worrying sales decline were strong sales of the smaller iPhone SE, a less-expensive model with a four-inch display launched in March. The $399 handset without a two-year contract managed to drag down the average sale price of all iPhones to $595 from $660 a year ago, with Cook reportedly saying during a call with analysts that the iPhone SE was extending the range of people able to buy Apple smartphones.

Apple-iPhoneSE The new iPhone SE is seen on display during an event at the Apple headquarters in Cupertino, California, March 21, 2016. Photo: REUTERS/Stephen Lam

“The customer demand for our products was significantly stronger than we had anticipated at the beginning of the quarter,” Luca Maestri, the Chief Financial Officer at Apple, told Bloomberg in an interview. “We were not able to fulfill iPhone SE demand throughout the quarter. We have now been able to put in enough capacity to provide sufficient supply for the next quarter.”

Because Tuesday’s results and Apple’s expectations for the current quarter ending September were better than what analysts expected earlier, the investors apparently realized that things are looking more hopeful at Apple than what has been perceived in a while. On Tuesday, Apple’s shares rose 7 percent to $103.47 in after-hours trade following the announcement of results. Up to the day’s close, the company’s shares had fallen about 8 percent since the start of the year.

However, strong sales of the iPhone SE couldn’t help Apple avoid an overall failure of its smartphone business in meeting the sales figures of its first batch of large-screen iPhones. The sales decline is partly attributed to the waning demand for iPhones in China, as well as to customers in more mature markets holding on to their handsets for longer than usual. Cook blamed the economic uncertainty in China for the 2 percent drop in iPhone sales in the country during the third quarter. However, he was still optimistic about the market, considering the massive surge last year.

“Over the long haul, we’re very bullish in China,” the Journal quoted Cook as saying. “There will be some potholes along the way and speed bumps, but I think China is an unbelievable place and I haven’t seen anything that causes me pause on that.”

Here is a look at the latest data:

Apple-Q3-results Apple released its Q3 earnings Tuesday. Photo: Apple

In addition to cooling demand in China, Apple is also facing aggressive completion from local manufacturers, including Huawei Technologies Co., which has started gaining traction in the global smartphone market. Huawei said Tuesday that it would ship 140 million smartphones in 2016, up 30 percent from 2015.

All these challenges in China have made Apple shift its focus to India, which is the fastest growing smartphone market in the world. Apple’s revenue jumped 51 percent in the country this year so far as the company expands into emerging markets.

“India is now one of our fastest growing markets,” Cook told analysts Tuesday. “We're looking forward to opening more retail stores in India down the road, and we see huge potential.”