You can implement this kind of functionality by using a combination Background fetch (Apple documentation) and local notifications, if you have a server inside the network that contains the information which is needed to show the notification. Conceptually this would work like this:
- Setup the app to fetch the data periodically from your server inside internal network using background fetch functionality.
- When the server sends you the information that should notify the user, show the local notification.
There are three things to remember in this approach, though.
- Your app does not receive the notification if it is not running in the background, ie your users will need to remember to keep the app running in the background.
- The background data fetch is not completely reliable, and Apple may not fire it on time ie. when the device is in the battery save mode. This may or may not be okay for your use case (you'd want to test it).
- You need to test that your iPhones do not disconnect from the wifi when going to the sleep mode; otherwise your background fetch logic will not work.
EDIT: For example like this:
- In project settings, enable Capabilities -> Background Modes -> Background fetch
- set minimum interval in your
AppDelegate.didFinishWithLaunchOptions
method, for example:
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
- implement the handler method in the AppDelegate:
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping
(UIBackgroundFetchResult) -> Void {
fetchData() { data in
if data.needsToBeNotified {
sendLocalNotification()
}
completionHandler(.newData)
}
}
RayWenderlich have a nice tutorial about the background modes: https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started