A California court has reportedly ordered a man to stay away from Apple CEO Tim Cook after the company accused him of stalking the tech honcho.

Apple won a temporary restraining order last week against Rakesh “Rocky” Sharma, who allegedly left flowers and champagne at Cook’s Silicon Valley property and tried to show him racy photos on Twitter, according to court records and reports.

Sharma’s efforts to harass Apple bosses dates back at least to last fall, when he left “disturbing” voicemails on an unidentified company executive’s phone, according to testimony from an Apple security specialist in court documents posted on Twitter

Sharma then started trying to stalk Cook by trespassing on his Palo Alto property twice within two months, says the testimony filed in Santa Clara County Superior Court.

Sharma came to Cook’s property on the night of Dec. 4, when he dropped off the flowers and champagne and then continued to tag Cook on his Twitter account, “which included sexualized and inappropriate photos of Mr. Sharma with reference to the Apple executive,” the testimony says. Sharma returned to the property on Jan. 15, when he snuck through a gate and rang the doorbell, court records say.

Sharma also allegedly claimed he knew where Apple executives lived on a call to the company’s technical support line and said, “I don’t use ammunition but I know people who do,” NBC News reported Thursday.

The restraining order, which expires the same day as a March 3 hearing in the case, directs Sharma to stay away from Cook, his property, Apple’s Cupertino, California headquarters, and the company’s executive team, according to NBC News.

An online case file shows a judge granted the restraining order on Feb. 13 and scheduled a March 3 hearing, but The Post could not access the full court filings. Excerpts from the documents were tweeted out by Dave Gershgorn, a senior writer for the technology news website OneZero.

Apple did not immediately respond to request for comment Friday morning.