我的应用可以通过 PushKit 接收后台通知。这些 PushKit 通知会触发一个操作来清理以前发送的常规通知。
当我终止应用程序并收到 PushKit 通知时,会在我的初始视图控制器上触发 viewDidAppear(如故事板中配置的那样)。这给我带来了一些问题。我了解 PushKit 在后台启动您的应用程序,但我不明白为什么会触发 viewDidAppear;因为该应用程序实际上从未打开过。
伪 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]
}
我想知道 viewDidAppear 通过 PushKit 触发是否是正常行为?初始控制器中的 viewDidAppear 启动了我的身份验证过程,我不希望在应用程序处于后台时发生这种情况。