Republican presidential candidate Donald Trump called for a boycott of Apple products until the tech giant cooperates with the FBI’s demand to help unlock the iPhone of one of the San Bernardino shooters.

“What I think you ought to do is boycott Apple until such time as they give that security number,” Trump said at a town hall event in South Carolina. “How do you like that? I just thought of that!”

Trump’s tweets after his call for the Apple boycott were all sent from an Apple iPhone.

Apple refused to cooperate after a US federal magistrate ordered the company to help the FBI unlock the iPhone, with the chief executive, Tim Cook, describing the demand as “chilling”. In a letter published on the company’s website, Cook responded by saying Apple would oppose the order and calling for public debate.

“The United States government has demanded that Apple take an unprecedented step which threatens the security of our customers. We oppose this order, which has implications far beyond the legal case at hand,” he wrote.

While Cook took pains to stress that Apple was “shocked and outraged” by the San Bernardino shooting last December – “we have no sympathy for terrorists” – he said company is determined to resist the court order.