简体   繁体   English

从后台终止应用程序后,UILocalnotification无法正常工作

[英]UILocalnotification not working after killing the app from background

I am working with UIlocalnotifications, So whenever a notification pops up,and user clicks on it I open ViewController , so whenever my app is in background, and when notification pops up and when user clicks on it or on the app icon, I am able to show the ViewController. 我正在使用UIlocalnotifications,因此,每当弹出通知并用户单击它时,我都会打开ViewController,因此每当我的应用程序在后台,弹出通知以及用户单击它或在应用程序图标上时,我就可以显示ViewController。

But whenever user kills the app from background, and when notification occurs, if he clicks on notification, I am able to show the ViewController, but if I click on app Icon, I am not able to show ViewController 但是每当用户从后台杀死应用程序时,以及当发生通知时,如果他单击通知,我都可以显示ViewController,但是如果我单击应用程序图标,则无法显示ViewController

Below is my code 下面是我的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (locationNotification) {
        // Set icon badge number to zero
        application.applicationIconBadgeNumber = 0;


       AlarmViewController *alarmView = [[AlarmViewController alloc]initWithNibName: @"AlarmViewController" bundle:nil];    
    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:alarmView];
    [self.window.rootViewController presentViewController:navController animated:YES completion:nil];

    }
}

I tried to debug this problem, and what I found is that, whenever I click on the app icon, its not getting any localnotification.Only if I click on the notification, I get a localnotification. 我尝试调试此问题,发现的是,每当我单击应用程序图标时,它都不会获得任何本地通知。只有单击通知后,我才能获得本地通知。 I dont know whenether this is a bug, or whether I am missing something. 我不知道什么时候这是一个错误,或者我是否缺少任何东西。

So please help me out 所以请帮帮我

Regards Ranjit. 问候兰吉特。

It's not a bug! 这不是错误! Handling Local and Remote Notifications in Apple's development library says 苹果开发库中的处理本地和远程通知

Handling Local and Remote Notifications 处理本地和远程通知

Let's review the possible scenarios when the system delivers a local notification or a remote notification for an application. 让我们回顾一下系统为应用程序传递本地通知或远程通知时可能发生的情况。

The notification is delivered when the application isn't running in the foreground. 当应用程序不在前台运行时,将发出通知。 In this case, the system presents the notification, displaying an alert, badging an icon, perhaps playing a sound. 在这种情况下,系统会显示通知,显示警报,标记图标,甚至播放声音。

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 application:didFinishLaunchingWithOptions: method (if implemented); 如果点击了操作按钮(在运行iOS的设备上),则系统将启动应用程序,并且该应用程序将调用其委托人的应用程序:didFinishLaunchingWithOptions:方法(如果已实现); 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 . 如果在运行iOS的设备上点击了应用程序图标,则该应用程序将调用相同的方法,但不提供有关通知的信息。 If the application icon is clicked on a computer running OS X, the application calls the delegate's applicationDidFinishLaunching: method in which the delegate can obtain the remote-notification payload. 如果在运行OS X的计算机上单击该应用程序图标,则该应用程序将调用委托的applicationDidFinishLaunching:方法,该委托可以在其中获取远程通知有效负载。

iOS Note: The application delegate could implement applicationDidFinishLaunching: rather than application:didFinishLaunchingWithOptions:, but that is strongly discouraged. iOS注意:应用程序委托可以实现applicationDidFinishLaunching:而不是application:didFinishLaunchingWithOptions :,但是强烈建议不要这样做。 The latter method allows the application to receive information related to the reason for its launching, which can include things other than notifications. 后一种方法允许应用程序接收与其启动原因有关的信息,其中可以包括通知以外的内容。 The notification is delivered when the application is running in the foreground. 当应用程序在前台运行时,将发送通知。 The application calls its delegate's application:didReceiveRemoteNotification: method (for remote notifications) or application:didReceiveLocalNotification: method (for local notifications) and passes in the notification payload or the local-notification object. 该应用程序调用其委托的application:didReceiveRemoteNotification:方法(用于远程通知)或application:didReceiveLocalNotification:方法(用于本地通知),并传入通知有效负载或本地通知对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 杀死应用后,后台获取功能无效 - Background fetch is not working after killing the app 更新应用程序后,UILocalNotification自定义声音无法正常工作 - UILocalNotification Custom Sound not working after updating app 背景中的UILocalNotification应用程序 - UILocalNotification App in Background 当应用程序进入后台或模拟器锁定时,UILocalNotification不起作用 - UILocalNotification is Not Working When app goes in background or simulator goes lock 从后台杀死应用程序后,应该在ios中运行gps跟踪应用程序(目标c) - After killing the app from the background, app should run gps tracking application in ios (objective c) 终止(完全关闭)应用程序后,UILocalNotificationAction不起作用 - UILocalNotificationAction is not working after killing (completely closing ) the app 当UILocalNotification触发时,将应用程序从后台自动带到前台吗? - Bringing an app from background to foreground automatically when an UILocalNotification fires? 应用程序关闭后,UILocalNotification为零 - UILocalNotification is nil after app closes 应用进入后台时终止连接 - Killing connections as app enters background MPMusicPlayerController.play() 在杀死 iOS 音乐应用程序后不起作用 - MPMusicPlayerController.play() not working after killing iOS music app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM