That's not very hard, read some documentationsome documentation about that. It will save you a lot of time.
iOS 6 also offers new features about this, but this is still under NDA at the moment.
Be sure to read the API changelogiOS 6 API changelog on Apple Developer website, if you can access to it.
Edit: As iOS 6 is now out,
And check the new iOS 6 AutoLayoutAutoLayout capabilities.
That said, if you really need to detect the iPhone 5, you can simply rely on the screen sizescreen size.
And obviously, if you need to detect an iPhone 6 or 6 Plus, use the corresponding screen sizes.
Final note
Comments and suggestions have been incorporated in this post.
Thanks to everybody.