Seems like every year we get a fruit fly infestation. I suppose they ride in on produce and set up housekeeping in my kitchen, then buzz around annoying me for a couple of months. Nothing is more aggravating than sitting my coffee down, and when I pick it up there's a fruit fly drowning in it. I also have to cover food (like salads or sliced tomatoes) on the dinner table. I made a trap with a small bowl of apple cider vinegar with a couple of drops of dish soap and placed it on my kitchen windowsill. I see about 5 fruit fly bodies floating in there so far today. I read on a agricultural extension website to wash ALL produce when bringing it into the house, whether from a garden or the grocery store. I don't typically wash bananas or citrus fruit, but I suppose I'll need to start doing that.
I take a Pepsi bottle, cut the top off it, turn it upside down in the bottle, put tape around it, then put a little bit of Kentucky Tavern in it. It draws fruit flies like bees to honeysuckle. They die happy, too.
Washing fruit is a good idea, but once you have them, I take a jar or wine glass and put some ripe peach nectar in it, then take a plastic funnel that is a bit larger at the top than the jar or glass but shorter in height, and put it on top with the spout down. Adios hijos de putas. If you are expecting company the wine glass is a good idea because you can quickly remove the funnel for a more inviting look.
Besides what has been mentioned, in the restaurants and bars where fruit flies are a definite no-no, we make sure the drains are crystal clean. Pour some bleach or boiling water down your drains at least once a day (including the shower) because that’s where they live. Kinda like mosquitos being born in water but they live on your shrub and tree leaves. Same principle. Fruit flies eat what they eat but they live in and around drains and such.
Adding to what Bobby said, garbage disposals are a major attraction for fruit flies and gnats so giving your disposal a shot of the Jussie Smollet Mega treatment is a good idea.
They are not a big problem here until late summer and early fall when outside fruits and vegetables begin to rot. Then I have seen swarms of them three feet across . I don't know of any way to keep all of them out of the house.