从远程推送通知打开视图时后退按钮消失
Back Button Disappear when view open from remote push notification
我在我的应用程序中使用了远程推送通知,当应用程序关闭并且通知出现在 iPhone 并且用户打开它时,应用程序在指定的视图上打开,在正常情况下这个视图有返回 viewcontrolA 的按钮,但是返回从通知中打开时按钮不好玩,我需要帮助来解决它。
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];
});
}
}
是的,因为您将 属性 详细信息 ViewController
设置为 UINavigationController
的根控制器。因此它不知道要导航的前一个 ViewController
。
后退按钮仅在导航堆栈中有要返回的视图时显示。
作为一个 UINavigationController
层次结构,我们的屏幕后退按钮默认显示,因为它是从列表页面导航的。当你从 Notification
过来的时候 viewcontroler
当时 属性 详情视图变成了 Rootviewcontrollers
。所以以下是逻辑。
以编程方式在详细信息视图控制器中设置后退按钮。在他们的活动中,您只需要检查 viewcontroler
是否已从推送的 viewcontroler
或 rootviewcontroller
打开,并根据条件编写代码。
如果打开viewcontroller 作为 rootviewcontrolr 然后在后退点击你需要添加新的 Rootviewcontroller 使用 window 对象。
否则返回工作完美弹出到 viewcontroller。
我在我的应用程序中使用了远程推送通知,当应用程序关闭并且通知出现在 iPhone 并且用户打开它时,应用程序在指定的视图上打开,在正常情况下这个视图有返回 viewcontrolA 的按钮,但是返回从通知中打开时按钮不好玩,我需要帮助来解决它。
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];
});
}
}
是的,因为您将 属性 详细信息 ViewController
设置为 UINavigationController
的根控制器。因此它不知道要导航的前一个 ViewController
。
后退按钮仅在导航堆栈中有要返回的视图时显示。
作为一个 UINavigationController
层次结构,我们的屏幕后退按钮默认显示,因为它是从列表页面导航的。当你从 Notification
过来的时候 viewcontroler
当时 属性 详情视图变成了 Rootviewcontrollers
。所以以下是逻辑。
以编程方式在详细信息视图控制器中设置后退按钮。在他们的活动中,您只需要检查
viewcontroler
是否已从推送的viewcontroler
或rootviewcontroller
打开,并根据条件编写代码。如果打开viewcontroller 作为 rootviewcontrolr 然后在后退点击你需要添加新的 Rootviewcontroller 使用 window 对象。
否则返回工作完美弹出到 viewcontroller。