I’m trying to build an app that can monitor several beacons even if the app is killed. Currently I’m able to receive notifications only when the startMonitoringBeaconRegion is called from within didFinishLaunchingWithOptions. If I try to call it from any other controller in the app it simply won’t work. The point is that I retrieve the information to identify the beacons at a later stage through an API call so I cannot use didFinishLaunchingWithOptions.
That’s expected behavior. When the app gets killed, all your ViewControllers are removed from memory. Then, when you enter range of a beacon you’re monitoring for, iOS will relaunch the app into the background, which means no ViewControllers will be created, only your AppDelegate class.
There are many patterns out there that will allow your ViewControllers (when the user opens the app and they get created) to access data from the AppDelegate. For example, in the AppDelegate, when you get enter/exit callbacks, you could use the
NSNotificationCenter to post internal notifications to other components in your app (such as VCs) about the enter/exit event.