James Martin/CNET

One night in early December, a man carrying a bottle of champagne and flowers showed up at Apple CEO Tim Cook's home. He returned a month later, entering the property's gate without permission and ringing the doorbell.

Those interactions -- along with phone calls, making what Apple describes in a legal filing as "threatening statements" -- led the company to request a restraining order this month against Rakesh Sharma, a 41-year-old San Francisco man.

A California court granted Apple a temporary restraining order against Sharma, who goes by "Rocky." He has been ordered to stay away from Cook's residence in Silicon Valley, as well as the CEO's three security guards. The order lasts through March 3, when a hearing is scheduled.

In a court document, Apple security specialist William Burns said Sharma's harassment began on Sept. 25, 2019, when he left a "disturbing" voicemail on "an Apple executive's phone." Sharma allegedly made another unsettling call about a week later. After that, Sharma's behavior "escalated," Burns said, to attempting "to stalk Apple's CEO by physically trespassing on the CEO's personal property" on two separate occasions.

Sharma entered Cook's property through a closed gate without permission at around 10:30 p.m. on Dec. 4 in an effort to deliver the flowers and champagne, a filing said. "Shortly thereafter, Mr. Sharma continued to tag the Apple executive on his Twitter account, which included sexualized and inappropriate photos of Mr. Sharma with reference to the Apple executive," it said.

Sharma returned to Cook's home on Jan. 15 but left before the Palo Alto Police Department arrived, Burns said.

Now playing: Watch this: The iPhone SE 2 March launch event is on the horizon

"Mr. Sharma's continuous and increasingly threatening conduct is causing me and other Apple employees significant emotional distress and gives me grave concern for our personal safety," Burns said.

Apple is one of the world's biggest companies, and Cook, CEO since 2011, is one of the world's most powerful and recognizable tech executives. It isn't a surprise that Cook and other Apple executives have alleged stalkers, nor that Apple would take steps to protect its employees.

Apple declined to comment. Sharma, when reached by CNET, described the interactions as a misunderstanding. He said he doesn't have an attorney representing him in this case yet.

A video Sharma posted to Twitter in early February criticized Cook.

"Hey Tim Cook, you have serious issues at your brand," he says. "You need to leave the Bay Area. Basically, I'm shooing you out. Shoo, Tim Cook, out of the Bay Area."

After allegedly trespassing on Cook's property, Sharma in February placed "two nonsensical" calls to Apple, Burns said in a filing. In one, he asked for a cash settlement because he said an "Apple employee laughed at him over the phone and hung up while Mr. Sharma was allegedly recovering in the hospital." Sharma told Apple that his attorney is Speaker of the House of Representatives Nancy Pelosi, according to a court filing.

Apple's attorneys sent Sharma a cease-and-desist letter on Feb. 5, telling him to not contact Apple and its executive team. That same day, Sharma called Apple's AppleCare tech support line and "made a number of highly disturbing and threatening comments," the filing said.

"During the call, Mr. Sharma stated that he knows where members of Apple's Executive Team lives and stated that 'I don't use ammunition but I know people who do,' that Apple's CEO is a criminal and that Apple tried to have Mr. Sharma killed while Mr. Sharma was in the hospital," Burns said. He added that Sharma "made other delusional and paranoid comments related to Apple."

A reporter from Medium's OneZero spotted the filings earlier Thursday.

CNET's Steven Musil and Andrew Morse contributed to this report.