大佬教程收集整理的这篇文章主要介绍了ios – 从通知中心点击时,UILocalNotification不会触发didReceiveLocalNotification,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([UIApplication sharedApplication].scheduledlocalnotifications.count >= 1) { // Handle local notification received if app wasn't running in BACkground UIlocalnotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionslocalnotificationKey]; if ([[notification.userInfo objectForKey:@"notification"] isEqual:@"mood rating"]) { // Create reportVC NSLog(@"launched app and about to show reportvc"); ReportViewController *reportVC = (ReportViewController *)[self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"reportVC"]; // Date stuff goes here - code removed // show the reportVC [self.window.rootViewController showViewController:reportVC sender:self]; } } else { [self createlocalnotification]; } return YES; }@H_618_5@这是我的didReceivelocalnotification代码: @H_618_5@
- (void)application:(UIApplication *)application didReceivelocalnotification:(UIlocalnotification *)notification { // Create report view ReportViewController *reportVC = (ReportViewController *)[self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"reportVC"]; // Same date stuff goes here as in didFinishLaunchingWithOptions // Show report vc [self.window.rootViewController showViewController:reportVC sender:self]; }@H_618_5@我已经拿出的日期内容只是检查它是否在晚上9点之后,创建今天的日期或昨天,然后将结果设置为reportVC的属性.如果这是相关的,请告诉我,我会重新加入. @H_618_5@所以这里有一些我试图解决的问题: @H_618_5@>我尝试过使用presentViewController:animated:completion:而不是showViewController:sender:但是我想使用showViewController,@R_2_9447@让导航栏出现,而且无论如何都没有解决问题.
[[UIApplication sharedApplication] cancelAlllocalnotifications]; [self createlocalnotification];@H_618_5@我将通知的预定时间更改为将来约3分钟.它通常设置为每晚9点使用这样的日期组件: @H_618_5@
dateComponents.hour = 21; dateComponents.minute = 0;@H_618_5@我将通知的repeaTinterval更改为NSCalendarUnitminute而不是NSCalendarUnitDay,这是它为发布版本设置的内容. @H_618_5@然后我使用XCode在我的设备上运行应用程序,并在运行后停止并安排通知.我没有这两行再次运行它: @H_618_5@
[[UIApplication sharedApplication] cancelAlllocalnotifications]; [self createlocalnotification];@H_618_5@然后从XCode停止应用程序,在我的设备上打开多任务处理,向上滑动应用程序以关闭它,然后等待通知到达.在点击每个测试通知后,我多次执行并再次关闭应用程序,以便每次都可以从完全关闭的应用程序进行测试.
if ([[notification.userInfo objectForKey:@"notification"] isEqual:@"mood rating"]) { dispatch_async(dispatch_get_main_queue(),^{ // Create reportVC NSLog(@"launched app and about to show reportvc"); ReportViewController *reportVC = (ReportViewController *)[self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"reportVC"]; // Date stuff goes here - code removed // show the reportVC [self.window.rootViewController showViewController:reportVC sender:self]; }); }@H_618_5@或者这个(在呈现视图控制器之前调用[self.window makeKeyAndVisible]): @H_618_5@
if ([[notification.userInfo objectForKey:@"notification"] isEqual:@"mood rating"]) { // Create reportVC NSLog(@"launched app and about to show reportvc"); ReportViewController *reportVC = (ReportViewController *)[self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"reportVC"]; // Date stuff goes here - code removed // show the reportVC [self.window makeKeyAndVisible]; [self.window.rootViewController showViewController:reportVC sender:self]; }
以上是大佬教程为你收集整理的ios – 从通知中心点击时,UILocalNotification不会触发didReceiveLocalNotification全部内容,希望文章能够帮你解决ios – 从通知中心点击时,UILocalNotification不会触发didReceiveLocalNotification所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。