Added code to support both iOS6 and iOS7+.