You can try a clean install of your device after a factory reset:
First make sure you have a backup
How to back up your iPhone, iPad, and iPod touch - Apple Support
Then facory reset your device:
Restore your iPhone, iPad, or iPod to factory settings - Apple Support
And set it up without a backup. See if the issue persists.
If it still does not work it is a hardware issue and will need service:
Contact Apple for support and service - Apple Support
If that solved it there was a software issue. Try restoring the backup and see if it still works.
if that made the problem come back the backup is the problem
Good luck!