How do I reliably undo typing on an iPhone, and are there better alternatives to shaking it?
There's no special motion for shake to undo; just shake the iPhone firmly in any direction, though not every app supports it. Since iOS 13 you can also undo by swiping left with three fingers or double-tapping with three fingers, and those work in all apps.