I did that by transferring purchases to computer first.
And then backup the iphone.
After that, I connect my new iPhone, and restore the backup I just did from previous iPhone.
As my experience, the apps data from old iPhone is going to my new iPhone. (like my song in garage band, files in adobe reader, etc)
After everything OK, then I reset all settings on my old iPhone, and sell it
Transfer data to new iPhone
Do this to wipe iPhone:
Wipe iPhone/iPad/iPod touch clean
There are a few steps to do:
Switch off iMessage in Settings > Messages
Switch off FaceTime in Settings > FaceTime (iPod touch 4th Generation or later, iPhone 4 or later and iPad 2 or later)
Delete iCloud in Settings > iCloud > Delete Account
Finally Settings > General > Reset > Erase All Content and Settings.
If your iPhone is registered: Un-register your device: https://supportprofile.apple.com
Now you can sell/give.
Message was edited by: ckuan