Apple's iPhone sales in China rose more than 18% last month, according to CNBC calculations using government data published by the China Academy of Information and Communications Technology, a government think tank.

Apple stock rose more than 2% on the news Thursday, reaching a new all-time high of $309.63 when markets closed.

Apple shipped 3.2 million iPhones in China through December, according to the data, and that figure was up from 2.7 million units shipped in December 2018. China is a key growth area for Apple, which has struggled against low-cost phone makers that sell Android phones.

In Q1 2019 Apple reported revenue from China of $13.17 billion, down $5 billion from the same time period in 2018.

"If you look at our results, our shortfall is over 100 percent from iPhone and it's primarily in greater China," Apple CEO Tim Cook told CNBC's Josh Lipton in an interview in January 2019. "It's clear that the economy began to slow there for the second half and what I believe to be the case is the trade tensions between the United States and China put additional pressure on their economy." The think tank data suggests sales have improved since then.

According to November data from Counterpoint Research, Apple had just 8 percent of the market share in China during the third quarter of 2019, down from 9 percent during the same time period in 2018. Huawei is the market leader with a 40 percent share, trailed by Vivo, Oppo and Xiomi.

The recent numbers on iPhone sales are a welcome sign of optimism in the crucial market, Wedbush analyst Dan Ives said in a note Thursday.

"This news only furthers our positive bullish thesis on Apple heading into 2020 given our recent positive Asia checks, 5G technology/upgrades around the corner, and our belief that China will continue this positive upward trajectory with renewed growth and share gains on the heels of an iPhone 11 product cycle which the skeptics continue to underestimate," he said.

Wedbush has an outperform rating and a 12-month price target of $350 on Apple stock.