My app can receive background notifications through PushKit. These PushKit notifications trigger an action to clean up previously delivered regular notifications.
When I terminate the app and receive a PushKit notification, viewDidAppear is triggered on my initial view controller (as configured in the storyboard). This is causing some problems for me. I understand that PushKit launches your app in the background, but I don't understand why viewDidAppear is triggered; as the app is actually never opened.
pseudo AppDelegate.swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
voipRegistration()
Messaging.messaging().delegate = self
// setup Firebase/Bugfender
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) {granted, _ in
// setup regular notifications
}
application.registerForRemoteNotifications()
return true
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers)
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
// register token with server
}
fileprivate func voipRegistration() {
let voipRegistry = PKPushRegistry(queue: nil)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [.voIP]
}
I wonder if it's normal behaviour that viewDidAppear gets triggered through PushKit? The viewDidAppear in the initial controller starts my authentication process and I don't want that to happen while the app is in the background.