Fruit flies are best controlled by locating and eliminating the source of the infiltration. Long-term presence of fruit flies indicates the larvae are breeding nearby. Breeding areas are usually in decaying organic material. Use an enzyme drain cleaner in the drains because treating drains with bleach or ammonia does not work.
From here on out the search broadens to all damp areas:
Sink and floor drains, garbage disposals, and damp cabinets from leaky drains,
Mops and mop buckets with old water,
Behind and under the oven and refrigerator,
Recycle bins, garbage pails, empty bottles and cans,
Adults can be controlled with flying insect killer and bug bombs. But the solution isn’t to store fruit in the refrigerator and moved the beer and pop cans out to the garage. To eliminate the problem the breeding ground must be sterilized.
Use an enzyme drain cleaner in the drains by mixing a 16-once treatment and pouring around the perimeter of the drain. Mix a double dose and pour into a running disposal shutting off the disposal just as you finish pouring. (Use caution not to get over-spray on yourself when pouring.)
Repair any leaks under cabinets and use a fan to dry the area quickly.
Clean mops and buckets with a disinfectant and store outside to dry.
Clean behind the oven and refrigerator with a disinfectant and dry completely.
Rinse cans and bottles and store in a sealed container.
Let the houseplants dry between watering.
Flytraps can be used to capture adults without pesticides. These work well in many instances when baited with red wine, red cider vinegar or fruit in a small amount of water.
Tip: Surround fruit out in the open with fresh basil.