When I close the app by swiping up on my iPhone I get an. message that the app needs to be open for thew lock to work.
that's not ideal since I always swipe up the apps to close them. Isn't there a way to make it work on the background?
No, IOS does not allow to work app in the background. You should not "close" the app if you want to use auto-unlock. It does not mean the app is doing something in the background, but it ensures the system can wake it up when needed.