Ipad and Iphone will not connect

I have to close the app on my phone or tablet several times before it will connect. If my phone/tablet goes to sleep, it will not connect unless I close the app. and reopen it. It is random on whether it will connect or not.