I thought this was a joke when I read it on OS X Daily, but I tried it, and it works on both the iPhone and iPad. Hit the link for the full explanation.

∞ How to Undo & Redo Typing on iPhone with a Shake | OS X Daily