If you have made your iOS device trust your computer, this is the best choice to unlock it and get all your data back. Just follow the steps (set iPhone as an example):
1) Plug your locked iPhone to computer you have trusted with;
2) Open your iTunes and backup your iPhone data to it;3) Click Restore iPhone to reset it.
If you want to erase your iOS device on iCloud, you must enable Find My iPhone service before and your device must have connected to a Wi-Fi or cellular network. This method can help you erase all your data including your passcode. You can do as the following (the same as iPad and iPod):
1) Enter iCloud.com on another iPhone or computer to sign in;2) Click Find iPhone > All Devices on the top of your browser window and choose a device you want to erase;
3) Click Erase iPhone to remove all your data as well as iPhone password;4) Begin to set up your iPhone and choose Restore from iCloud Backup to get your previous data.
If you did not sync your iDevice to iTunes or set Find My iPhone on iCloud before, you can use this mode to reset your iOS device and remove your setup for its passcode.
1) Connect your iOS device to computer and open iTunes;2) Press and hold the Wake/Sleep button to restart your device until you see the recovery mode screen;