First, open your project in Xcode, select your Runner and then Signing & Capabilities tab. In the Background Modes section, make sure to enable:
- Audio, AirPlay, and Picture in Picture
- Background fetch
This allows the app to check alarms in the background.
Then, open your Info.plist and add the key Permitted background task scheduler identifiers
, with the item com.gdelataillade.fetch
inside.
It should add this in your Info.plist code:
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.gdelataillade.fetch</string>
</array>
This authorizes the app to run background tasks using the specified identifier.
Open your AppDelegate and add the following imports:
import UserNotifications
import alarm
Finally, add the following to your application(_:didFinishLaunchingWithOptions:)
method:
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
}
SwiftAlarmPlugin.registerBackgroundTasks()
This configures the app to manage foreground notifications and setup background tasks.
Don't forget to run pod install --repo-update
to update your pods.