gpt4 book ai didi

iphone - iOS UILocalNotification - 当应用程序在后台运行并且在通知时单击图标时,不会触发委托(delegate)方法

转载 作者:行者123 更新时间:2023-12-03 18:21:25 24 4
gpt4 key购买 nike

iPhone 版本 - 5.1 (9B176)

下面是本地通知期间的一系列事件,其中未调用 didFinishLaunchingWithOptions 方法。

  1. 应用程序正在后台运行。
  2. 收到本地通知 - 简单通知,无对话框。
  3. 点击显示徽章编号的应用图标。

预计按照Apple documentation :

As a result of the presented notification, the user taps the action button of the alert or taps (or clicks) the application icon. If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s didFinishLaunchingWithOptions method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).

If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification

实际:didFinishLaunchingWithOptions 未调用。但是 applicationWillEnterForegroundapplicationDidBecomeActive 被调用。

最佳答案

你是对的。该行为与文档不一致。把文档放在一边,关注实际行为;问题的关键似乎是这样的:如果您的应用程序通过用户与通知交互而变得活跃,您将收到一个指向通知的指针,如果用户直接点击您的应用程序图标,您将不会收到。

举例说明。如果您呈现警报样式通知并且用户点击操作按钮,或者像您的情况一样,如果您呈现横幅通知并且用户点击,您将通过以下两种方式之一收到指向通知的指针:

如果您的应用程序处于“未运行”状态:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UILocalNotification *launchNote = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (launchNote){
// I recieved a notification while not running

}
}

如果您的应用程序在任何状态下运行:

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
// I recieved a notification
}

如果用户选择取消警报样式通知,该通知就会消失。

真正令人烦恼的不一致部分是,如果您呈现横幅通知并且用户点击您的图标,您似乎无法检索对通知中心中呈现的通知的引用。即,它们不会出现在 [[UIApplication sharedApplication] ScheduledLocalNotifications] 数组中,大概是因为它们不再被调度,但现在已呈现。

简而言之;文档是错误的。还有其他令人烦恼的不一致之处。如果此行为对您来说是个问题,您应该向 Apple 提交错误。

关于iphone - iOS UILocalNotification - 当应用程序在后台运行并且在通知时单击图标时,不会触发委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9891460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com