Apple helped US prosecutors extract information from iPhones for years before refusing to assist the FBI in hacking a device belonging to one of the San Bernardino shooters.

Federal agents have claimed the technology giant assisted them at least 70 times before they suddenly rejected a request to break into the iPhone of an alleged drug dealer - weeks before the California massacre.

When 14 people were killed by Syed Farook and Tashfeen Malik in December, Apple was already embroiled in a court case arguing it was "being forced to become an agent of law enforcement" by breaking into customers' phones for the authorities.

In October, a lawyer compared forcing Apple to extract data from iPhones to forcing a safe manufacturer to travel across the US in order to pick locks at the government's whim.

Apple is now preparing legal arguments against the FBI's request for the company to create software which would allow investigators to have unlimited guesses at Farook's passcode.

Video:Apple Takes On The US Government

Intelligence authorities claim lives will be at risk if they cannot obtain the information on his iPhone.

At present, the FBI only has 10 chances to guess the PIN before the data on the device is wiped.

Tim Cook, Apple's chief executive, has called on the US government to withdraw its demand for assistance - and rejected claims that the California-based company is acting out of business interests.

Video:Trump: Boycott Apple Over Passcode

Several relatives of those killed in the San Bernardino attack support the US government's position.

Farook's iPhone came into the FBI's custody after he and his wife, who were inspired by Islamic State, died in a gun battle with police.

In an email to Apple employees, Mr Cook said "this case is about much more than a single phone or a single investigation".