Back Button Disappear when view open from remote push notification

时间:2016-03-02 10:50:48

标签: ios objective-c apple-push-notifications

I used remote push notification in my app, when app are closed and notification appear on iPhone and user opened it, app opened on specified view, in normal this view have back button to viewcontrolA, but back button not fun when open from notification, I need help to solve it.normal view when open from app view when opened from remote push notification

didFinishLaunchingWithOptions:

     if (launchOptions != nil)
        {
            NSDictionary* dictionary1 = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
            NSDictionary* dictionary2 = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
            if (dictionary1 != nil)
            {
                NSLog(@"Launched from push notification: %@", dictionary1);
                double delayInSeconds = 7;
                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                    //   [self addMessageFromRemoteNotification:dictionary1 updateUI:NO];
                });

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
            UIStoryboard *story=[UIStoryboard storyboardWithName:@"MainiPad" bundle:nil];
            MFSideMenuContainerViewController *controller=(MFSideMenuContainerViewController*)self.window.rootViewController;
            UINavigationController *mainVC=[story instantiateViewControllerWithIdentifier:DetailsSearchNav];
            [self.window makeKeyAndVisible];
            [controller.shadow setOpacity:0.75f];
            [controller setCenterViewController:mainVC];
            UIViewController *leftController=[story instantiateViewControllerWithIdentifier:@"LeftSideViewController"];
            [controller setRightMenuViewController:leftController];
            [controller setLeftMenuViewController:nil];
            }

            if (dictionary2 != nil)
            {
                NSLog(@"Launched from dictionary2dictionary2dictionary2 notification: %@", dictionary2);
                double delayInSeconds = 7;
                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                    // [self addMessageFromRemoteNotification:dictionary2 updateUI:NO];
                });
            }

        }

3 个答案:

答案 0 :(得分:3)

Back button only shows when there is a view to go back in navigation stack.

答案 1 :(得分:1)

作为UINavigationController层次结构,我们的屏幕后退按钮默认显示,因为它从列表页面导航。当你从viewcontroler来到Notification时,属于Detauls的视图变为Rootviewcontrollers。以下是Logic。

  • 以编程方式在Details View控制器中设置后退按钮。对于他们的活动,您只需要检查viewcontroler是否已从推送viewcontrolerrootviewcontroller打开,并根据条件制作代码。

  • 如果openviewcontroller作为rootviewcontrolelr然后在后面单击,则需要使用window对象添加新的Rootviewcontroller。

  • 此外,返回工作的parfect弹出到viewcontroller。

答案 2 :(得分:0)

Yes because you are setting Property Details ViewController as the root controller of UINavigationController. Hence it doesn't know the previous ViewController to navigate.