Posted this almost a year ago but I haven’t realised til now it wasn’t it’s own comment so in the interest of helping more people, here’s what has worked consistently for me since then - I still have the same iPhone and still use the same method to charge it, even though apple told me the ONLY solution was to get a new one!! Enjoy :)
Step 1: plug in your phone and dismiss the error message
Step 2: turn off your phone, leaving the charger plugged in
Step 3: leave for a couple of hours or as long as your phone usually takes to charge
Step 4: turn your phone back on. It will have charged as turning it off means you don't give it a chance to come up with the error message!
You'll have to do this each time you need to charge - it might be inconvenient but it's better than a dead phone! Hope this helps :)