我已为Firebase通知注册了该应用,并且已实施UNUserNotificationCenterDelegate
。didReceive
当应用程序正在运行或在后台运行时,将调用该方法。
当我终止应用程序并发送通知时。该willFinishLaunchingWithOptions
和didFinishLaunchingWithOptions
方法被称为但是launchOptions对象是零,不包含任何.remoteNotificaiton关键。
if launchOptions != nil {
logger.log("There is stuff in launch options")
}
我的AppDelegate设定
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
@available(iOS 10, *)
extension AppDelegate: UNUserNotificationCenterDelegate
extension AppDelegate: MessagingDelegate
上面的代码从不将任何日志消息打印到控制台。
我已经尝试了所有内容,并为整个Google进行了搜索,但没有具体内容。
我使用的是iOS 14 beta 6和Xcode beta 6。
提前致谢。
您可以从SceneDelegate而不是AppDelegate获得通知 connectionOptions.notificationResponse
来自https://dev.to/nemecek_f/ios-13-launchoptions-always-nil-this-is-the-reason-solution-kki和https://stackoverflow.com/a/61322065/12208004
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let notificationResponse = connectionOptions.notificationResponse {
// you can get notification here
}
let contentView = ContentView()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
[UPDATE]userNotificationCenter
即使未启动应用程序,您也可以收到通知
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
print("open notification")
let userInfo = response.notification.request.content.userInfo
print(userInfo)
completionHandler()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句