gpt4 book ai didi

ios - 如何在 appdelegate 中推送导航?

转载 作者:行者123 更新时间:2023-11-29 11:44:41 25 4
gpt4 key购买 nike

我已经成功地实现了推送通知,但是如何从 didReceiveRemoteNotification 方法推送导航。

我的代码

Appdelegate 代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

sleep(3);
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

[self registerForPushNotification:[UIApplication sharedApplication]];
if (launchOptions != nil)
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if (dictionary != nil)
{
NSLog(@"Launched from push notification: %@", dictionary);
[self handlePush:application forRemoteNotification:dictionary];
}
}
[self setupMainPage];
[self.window makeKeyAndVisible];
return YES;
}

- (void)setupMainPage
{
if([[[NSUserDefaults standardUserDefaults] valueForKey:@"LoggedIn"] isEqualToString:@"0"])
{
if([[[NSUserDefaults standardUserDefaults] valueForKey:@"firstLaunch"] isEqualToString:@"0"])
{
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"firstLaunch"];

IntroVC *introView = [[IntroVC alloc] initWithNibName:@"IntroVC" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:introView];
[self.navController setNavigationBarHidden:YES];
}
else
{
LoginVC *loginVC = [[LoginVC alloc] initWithNibName:@"LoginVC" bundle:[NSBundle mainBundle]];
self.navController = [[UINavigationController alloc] initWithRootViewController:loginVC];
}
}
else
{
HomeVC *homeView = [[HomeVC alloc] initWithNibName:@"HomeVC" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:homeView];
}
self.window.rootViewController = self.navController;
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"%s",__FUNCTION__);
NSLog(@"USER INFO - %@",userInfo);
for (id key in userInfo)
{
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}

[self handlePush:application forRemoteNotification:userInfo];
}





-(void)handlePush:(UIApplication *)application forRemoteNotification:(NSDictionary *)userInfo
{
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
NSLog(@"%@",userInfo);
//NSString *pushType = [[[userInfo valueForKey:@"aps"] valueForKey:@"type"] lowercaseString];

pushAlert = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
pushType = [[userInfo valueForKey:@"aps"] valueForKey:@"type"];
NSInteger pushBadge = [[[userInfo valueForKey:@"aps"] valueForKey:@"badge"] integerValue];
strReciverId = [CommonUtils getNotNullString:[[userInfo valueForKey:@"aps"] valueForKey:@"receiver_id"]];
if (pushBadge > 0) {
[application setApplicationIconBadgeNumber:pushBadge];
}
// aceept request
if ([pushType isEqualToString:@"palrequest"])
{
[CommonUtils alertViewDelegateWithTitle:AlertTitle
withMessage:pushAlert
andTarget:self
forCancelString:@"View Invitation"
forOtherButtonString:@"Cancel"
withTag:101];
}
}



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;

if (alertView.tag == 101)
{
MyMatchesVC *myMatchesVC = [[MyMatchesVC alloc] initWithNibName:@"MyMatchesVC" bundle:nil];
myMatchesVC.strType = pushType;
[navigationController pushViewController:myMatchesVC animated:YES];

}

}

推送工作完美,但我的问题是当我推送然后自动更改我的 Root View 时。

我的应用流程

  1. 登录到应用程序,然后我更改了我的 Root View (Homeview Controller )
  2. 现在我收到了来自其他用户的通知,然后我点击查看邀请,然后推送到我的比赛。
  3. 现在我从比赛中回来,然后它变成了登录

需要这个结果

  • when i back from mymatch then pop to home view controller

请帮我解决这个问题。

最佳答案

试试这个!简单的解决方案:)

if (alertView.tag == 101)
{
MyMatchesVC *myMatchesVC = [[MyMatchesVC alloc] initWithNibName:@"MyMatchesVC" bundle:nil];
myMatchesVC.strType = pushType;
[self.window.rootViewController showViewController:myMatchesVC sender:self];


}

//如果你已经有了 MyMatchVC。请遵循以下样式。

  UINavigationController *snNavShareVC = (UINavigationController *)self.window.rootViewController;
NSArray *viewControllers = snNavShareVC.viewControllers;
UIViewController *findViewController = nil;
for (UIViewController *vc in viewControllers) {
NSLog(@"%@",[vc class]);
if ([MyMatchesVC class] == [vc class]) {
findViewController = vc;
}
}
if (findViewController) {
[findViewController updateView:pushType]; // Write method to update view
} else {
MyMatchesVC *myMatchesVC = [[MyMatchesVC alloc] initWithNibName:@"MyMatchesVC" bundle:nil];
myMatchesVC.strType = pushType;
[self.window.rootViewController showViewController:myMatchesVC sender:self];

}

//尝试在导航 Controller 中添加堆栈 View Controller 。

    ChatListVC *chatList = [[ChatListVC alloc]initWithNibName:@"ChatListVC" bundle:nil]; ChatDetailsVC *chatDetail = [[ChatDetailsVC alloc]initWithNibName:@"ChatDetailsVC" bundle:nil]; 
chatDetail.strReceiverId = strReciverId;
NSMutableArray *controllers = [self.navController.viewControllers mutableCopy];
[controllers addObject:chatList];
[controllers addObject:chatDetail];
[self.navigationController setViewControllers:controllers];

关于ios - 如何在 appdelegate 中推送导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44581196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com