Here is some useful code for myself in iOS.