I do something similar to -> https://gist.github.com/stefanpenner/f7383012b3c5bc640a9d in our apps, to deal with this case.