Apple is being sued in federal court by Epic Games, the maker of the "Fortnite" video game, which claims Apple acts anticompetitively by only allowing Apple approved apps access to the 1 billion iPhones around the world and then forcing developers to use Apple's in-app payment system, which takes up to a 30 percent cut of sales.

In Cook's testimony, his most extensive public comments on the App Store - which anchors Apple's $54 billion services business, he told the court that threats to iPhone security and privacy required tight control of the App Store.

Apple has sought to persuade the judge presiding over the antitrust trial that all the tech giant's rules for app developers are aimed at keeping customer data private and safe from malware.

But Cook did get some pushback from Judge Yvonne Gonzalez Rogers, who questioned Cook about the profits Apple reaps from game developers, which she said helped subsidize other apps and "appear to be disproportionate."

Apple is facing backlash from app makers including music service Spotify, European regulators, and some U.S. politicians, who claim the $2 trillion tech company has become too big and is using its size to squash the competition.