Ceratitis capitata, one of the commonest fruit flies (Wikipedia)
The flies lay their eggs in the fruit, just under the surface. When they hatch the little larvae happily eat away, safe from any predators, or indeed insecticide. When ready they emerge and drop to the ground where they pupate and later emerge to fly away, the whole process taking about 20-30 days. In at least some species the male fly then does a little dance to attract his mate. Of course all this does not make the fruit very attractive, and it also causes it to fall prematurely.
It's not just oranges - guava, peach, tangerine, cherry, cashew, mango, acerola, jabuticaba, passion fruit, cashew, hog plum, and star fruit all suffer. Arabica coffee as well, not so much as the others, but it can act as a nursery for fruit flies, who then fly to orchards nearby. One of the few fruits with some resistance is papaya, probably because of repellents and toxins in the latex of unripe fruit. Even then, if infected with sticky papaya disease up 60 pupae can be found in each fruit.
Ceratitis capitata larva (Wikipedia)
There is not just one species of fruit fly, far from it. The small Brazilian state of Espirito Santo has at least 41 species recorded. Terry Pratchett invented a God of Beetles, who made each one individually, there should probably be such a God for fruit flies as well!
Of course fruit flies don´t have it all their own way. Farmers spray against them, although the larvae are safely inside the fruit, and it can take quite a lot of insecticide to cover an orchard. One novel solution is to spray just a few trees with sugar solution, which attracts all the adult flies where they can be dealt with in a killing zone. And of course, for any herbivore there are predators. Parasitic wasps lay their own eggs in the fly larvae, and this can be so devastating to fly numbers that artificial rearing of these wasps is being considered - not very nice, but it is environmentally friendly.