I know you have asked how to do it programmatically. However, there is already an accessibility feature for your problem.
Go to Settings > General > Accessibility. Enable Guided Access and set a password. Once it is enabled, open your app and triple-click the home button. Your cat won't be able to leave the app even by clicking the home button.