Although there are pesticides for flies, many people do not want to use them for fruit.
The cheapest way to get rid of flies is apple cider vinegar... Put vinegar in a bowl. Cover it with cling film. You should make holes on the stretch films. This method will attract flies and no flies will be placed on the fruit.
If you do not have apple cider vinegar at home, you can also use grape cider vinegar.
Another method that saves fruits from flies is to attach mosquito nets to the windows. Be sure to protect your fruits in the fruit basket.
That's how simple it is to preserve fruits.