简体   繁体   English

无法从iOS中的本地通知重定向到特定屏幕

[英]unable to redirect to particular screen from local notification in iOS

I have built notification based application in iOS now I am getting issue is that when notification appears on screen, unable to redirect to particular screen containing its data. 我已经在iOS中构建了基于通知的应用程序,现在我遇到的问题是,当通知出现在屏幕上时,无法重定向到包含其数据的特定屏幕。 One thing I have observed is that If I NSLog it,I get all the values of that particular notification but screen does not get load. 我观察到的一件事是,如果我NSLog,我会获得该特定通知的所有值,但屏幕不会得到加载。 Am i missing something while integrating local notification hierarchy code ? 集成本地通知层次结构代码时,我是否缺少任何内容?

Thanks in advance for your help !! 在此先感谢您的帮助 !!

Here is code in Appdelegate. 这是Appdelegate中的代码。

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    UIApplicationState state = [application applicationState];

    if (state == UIApplicationStateActive) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reminder"
                                                        message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }

       if([[notification.userInfo valueForKey:@"note"]isEqualToString:@"note"])
       {
         // nsuserdefault...
            NSDateFormatter *dateFormatterN = [[NSDateFormatter alloc] init];
            [dateFormatterN setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
            NSString *currentTimeN = [dateFormatterN stringFromDate:notification.fireDate];


        NSUserDefaults *prefnote=[NSUserDefaults standardUserDefaults];
        [prefnote setObject:currentTimeN forKey:@"dateobject"];
        [prefnote setObject:@"notification" forKey:@"notification"];
        [prefnote synchronize];


        NSBundle *bundle = [NSBundle mainBundle];
        NSString *storyboardName = [bundle objectForInfoDictionaryKey:@"UIMainStoryboardFile"];

        UIStoryboard *storyboardNote = [UIStoryboard storyboardWithName:storyboardName bundle:nil];


      UIViewController *vc1Note = [storyboardNote instantiateViewControllerWithIdentifier:@"Home"]; //if you assigned this ID is storyboard
        UIViewController *vc2Note = [storyboardNote instantiateViewControllerWithIdentifier:@"AddNote"];  //if you assigned this ID is storyboard


           NSArray *controllersNote = @[vc1Note,vc2Note];

        UINavigationController *navControllerNote = (UINavigationController *)self.window.rootViewController;

        [navControllerNote setViewControllers:controllersNote];

    }
}

I have used IF condition as I have 3 categories and based on particular category It will be redirected to different screen. 我使用了IF条件,因为我有3个类别,并且基于特定类别,它将被重定向到其他屏幕。

You have created a new UINavigationController instance and set view controllers in this new navigation controller. 您已经创建了一个新的UINavigationController实例,并在此新的导航控制器中设置了视图控制器。 However you have not presented the nav controller. 但是,您尚未提供导航控制器。

You need to either 你需要

  • show you new navigation controller by either adding it to an existing view or replacing existing view 向您显示新的导航控制器,方法是将其添加到现有视图或替换现有视图

or 要么

  • push the view controllers to an existing navigation controller (which is already visible) instead of creating a new one. 将视图控制器推到现有的导航控制器(已经可见),而不是创建一个新的。 But note that only the last view controller you push will be visible. 但是请注意,只有您推送的最后一个视图控制器才可见。

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

相关问题 锁定屏幕iOS上的本地通知 - Local Notification on locked screen ios Flutter:当应用程序处于后台但未在 iOS 中终止时,无法在通知单击时重定向到特定屏幕 - Flutter : Unable to redirect to specific screen on Notification click when app is in background but not terminated in iOS 获取本地通知时重定向到特定的视图控制器 - Redirect to particular view controller when getting local notification ios 本地通知 - 摆脱锁定屏幕上的“通知”文字 - ios local notification - get rid of “Notification” text on the lock screen 仅在锁定屏幕且未激活屏幕时才显示iOS本地通知? - iOS local notification only when the screen is locked and without screen activation ? 从AppDelegate重定向到“特定屏幕”:点击通知 - Redirect to Specific screen from AppDelegate : On tap Notification 在特定时间后如何取消iOS本地通知? - How do I cancel an iOS local notification after a particular time? iOS 11目标C中特定时间的每日计划本地通知 - Daily schedule local notification at particular time in ios 11 objective c iOS 10:一旦在特定日期触发,如何重复本地通知? - iOS 10: How to repeat local notification once fired on particular date? 当手机进入锁屏iOS时如何触发本地通知 - How to trigger a local notification when phone goes to lock screen ios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM