处理应用程序终止时点击本地通知 - iOS- Swift
我想在终止应用程序时处理点击本地通知,但是方法应用程序中没有启动选项dodfinishlaunchingwithoptions
,而方法application
diDReceive didreceive noce
。
我还尝试实现两种unusernotificationcenterdelegate
:
1)处理通知,当应用在后台但不终止:
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
)
2)和下一个处理通知时, 前景:
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
)
不知道如何处理...
I want to handle tap on local notification, when the app is terminated, but there are no launch options in method application didFinishLaunchingWithOptions
and no call of method application didReceive notification
.
I also tried to implement two methods of UNUserNotificationCenterDelegate
:
1)Handles notification, when app is in background, but not terminated:
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
)
2)And next handles notification, when app is in foreground:
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
)
Have no idea how to handle it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您点击通知中心上的推送通知时。
OS启动您的应用程序(之前终止),然后仍然将操作传递给此(功能1)
您可以从响应中获得
Notification
对象,就像您所做的那样。但是,您可能需要从所选的推送通知中保存临时数据,然后在用户完全活跃时将其处理。
请记住,完成逻辑后,请致电
positionhandler()
。而且,您必须设置unusernotificationcenter.current()。delegate = self
,在您返回true
inself
以下是您的appdelegate < /code>,这意味着您将Usernotification的委派设置为实时对象或初始化对象。
它将能够处理上述委托函数调用(功能1)以获取所选的推送通知数据。
When you tap on Push Notification on Notification Center.
OS launches your app (terminated before) then STILL delivers the action to this (Function 1)
You can get the
notification
object from response like what you did.But you may need to save temporary this data from the selected push notification, then handle it later when app is completely active with user.
Remember to call
completionHandler()
when you finish your logic. And, you must setUNUserNotificationCenter.current().delegate = self
, before youreturn true
inself
here is yourAppDelegate
, which means you set UserNotification's delegate to a live object or initialized object.It will be able to handle the above delegate function call (Function 1) to get your selected push notification's data.