首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >推送通知的推送视图

推送通知的推送视图
EN

Stack Overflow用户
提问于 2012-04-27 06:11:59
回答 1查看 4.5K关注 0票数 2

我成功地收到了iOS 5的通知。当用户在通知中心滑动或点击推送通知时,我希望能够将用户发送到特定的视图。

我想让用户转到的视图控制器(视图),而不是我的应用程序的开头就是"groceryStoreViewController“。我读到这是在didFinishLaunchingWithOptions或didReceiveRemoteNotification中完成的,但我不确定。

如果有人知道如何做到这一点,我会非常感激,因为这真的是一场斗争。

谢谢

编辑

所以问题是,当用户点击通知时,我希望打开一个特定的视图控制器,但我也希望UITabBar保持不变。我没有成功地做到这一点,这与我展示我所相信的子视图有关。请告诉我你的想法,非常感谢。

代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

self.tabBarItem = [[[UITabBarItem alloc] init] autorelease];

 exploreViewController *view1 = [[exploreViewController alloc] initWithNibName:@"exploreViewController" bundle:nil];
view1.title= @"Explore";

Upcoming *view2 = [[Upcoming alloc] initWithNibName:@"Upcoming" bundle:nil];
view2.title = @"Upcoming";

TipsViewController *view3 = [[TipsViewController alloc] initWithNibName:@"TipsView" bundle:nil];
view3.title = @"Tips";

UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:view1];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:view2];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:view3];

[view1 release];
[view2 release];
[view3 release];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nil];
self.tabBarItem = [[[UITabBarItem alloc] init] autorelease];

[nav1 release];
[nav2 release];
[nav3 release];


if (launchOptions != nil)
{  
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
NSLog(@"Launched from push notification");
//Accept push notification when app is not open
if (remoteNotif) {      

 NSDictionary *alertBody = [remoteNotif objectForKey:@"loc-key"];

 self.window.rootViewController = nav2;  //this is what I want displayed when tapped but also maintain tab bar controller
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

  }
}
else {

    //Go here if just loading up normally without push
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

}
  return YES;

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-27 06:48:01

它是用didFinishLaunchingWithOptions:方法实现的。您可以检查应用程序是否由于通知而启动,并将适当的viewController设置为显示。

类似于:

代码语言:javascript
复制
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // other stuff

    if (launchOptions != nil) {
        NSLog(@"Launched from push notification");
        NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        // Do something with the notification dictionary
        self.myViewController = [LaunchFromNotificationViewController alloc] init];
    } else {
        self.myViewController = [OrdinaryLaunchViewController alloc] init];
    }

    self.window.rootViewController = self.myViewController;
    [self.windows makeKeyAndVisible];
    return YES;
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10345624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档