Think of your two sentences as responses to questions. Perhaps doing so will reveal how different they could be.
Question: Sylvia gave Janice a banana, but what did she give Harold?
Answer: Sylvia gave him an apple.
Question: Did Sylvia give the apple to him or to her?
Answer: Sylvia gave the apple to him.
The way in which sentence one is worded could indicate the questioner is more concerned about who received the apple than what the recipient received.
The way in which sentence two is worded could indicate the questioner is more concerned about the recipient of the apple than what the recipient received. Notice, however, I did change the "an" to "the."
Notice that I said the two sentences could be different. In practical terms, however, there could also be no difference--or only a very slight difference, depending on how precise the questioner wants to be. The questioner in each question need not have phrased the question in the same way. See if each of the following responses is significantly different.
Question: Did Sylvia reward her student in any way?
Answer: She gave him an apple.
Question: How do you know Sylvia rewarded her student?
Answer: She gave an apple to him.
In each of the answers above, neither the recipient nor what the recipient received is necessarily emphasized; rather, the entire sentence qua sentence provides the emphasis.
There are possibly other ways to phrase answers to each question, but I won't confuse things more than I probably have already! The point is, there is probably no hard and fast rule which will answer your question. That's the nature of the beast, so to speak. The "answer" needs to be "It depends." Sometimes what the answer depends on is a person's preference as to which sounds better or more natural to him or her.