When you do something affectionately, you do it in a way that shows fondness and warm feelings toward someone. Patting your dog's head affectionately may earn you a tail wag.
The adverb affectionately comes from the noun affection, which means "a gentle feeling of fondness or liking." Punching someone's shoulder affectionately will likely elicit a smile as opposed to a sneer, as it wasn't intended to hurt but rather to show friendship. The word affectionately evokes acts of kindness and warmth, like a loving smile, a gentle touch, or encouraging words — expressing genuine care for someone special in your life.