My guavas get worms.
My guava fruit gets worms. What can I do to prevent this?
Identifying the pest is important in order to get specific control recommendation. But there are some general considerations. Don't underestimate the importance of good soil and water management, and sanitation.
Starting early with preventive control measures is important, it is difficult to control an active infestation.
From my experience growing mangoes and guavas which are both susceptible to fruit fly infestation, the pheromone and vinegar traps are least effective because they only get a percent of adult flies and leave many more to infest the fruit. The bagging method and early harvest if possible is best, along with good growing conditions and sanitation.
This is from Australia, but you may find something similar in SA, or make your own.
Organic botanical pest repellents need frequent spraying, every week during peak infestation times and are marginally effective for fruit flies, if that's what it is.
I'm an American arborist, I've been to SA twice but never worked there, so you may want to seek local professional advise for identification and treatment recommendations.
These articles may help:
I have not used the biological controls and sterile fly release methods, but that is something to consider.