I do something similar in an app and here is a post with example code:
Hopefully that gets you going.