Pheromones attract and help to kill the males, so they cannot mate with the females. And without mating, female fruit flies will not be able to lay eggs. To attract and kill the male flies with pheromones, you need to use traps to protect the products from the rain. Certain traps are sold in the shop, but you can also make your own traps.
Note: This video contains some content referring to pesticides