This has been an ongoing problem for a while. The reason it's gone on so long without being sorted is cos it only happens odd times like once every few week. I have iPhone 6s it sometimes switches off with battery remaining normally 20% or less but has with up to 30%. When it switches off and I switch it back on it gives the needing charging sign then 2nd time comes back on but goes back off after few seconds. Sometimes it will come back on and stay on. If it won't stay on I have to put it on charge for a minute for it to stay on then I can take it off and it stays on. I have tried reseting my phone and running battery to 0% and none work. I have noticed me switching it off or restarting it when battery is low 20% or less increases chance of it not coming back on without being on charge.