从推送通知推送视图 [英] Push view from push notification

查看:115
本文介绍了从推送通知推送视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I receive my notifications successfully for iOS 5. I want to be able send users to a specific view when they swipe or tap the push notification in the notification centre.

视图控制器(视图)我希望用户反对我的应用程序的开始就是groceryStoreViewController。我已经读过这是在didFinishLaunchingWithOptions或didReceiveRemoteNotification中完成的,但我不确定。

The view controller (view) I want the user to go to opposed to just the start of my app is the "groceryStoreViewController". I have read that this is done in didFinishLaunchingWithOptions or didReceiveRemoteNotification but I am not sure.

如果有人知道怎么做,我真的很感激,因为它确实是一场斗争。

If anyone knows how to do this, I would really appreciate it since it has really been a struggle.

谢谢

编辑

所以问题是我希望在用户点击通知时打开特定的视图控制器,但我也希望保留UITabBar。我没有成功地做到这一点,它与我显示我相信的子视图有关。请让我知道你的想法并非常感谢你。

So the issue is that I want a specific view controller to be opened when the user taps a notification but I also want the UITabBar to remain. I have not successfully been able to do this and it has something to do with me displaying the subview I believe. Please let me know what you think and thank you so much.

- (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;

}


推荐答案

这是在 didFinishLaunchingWithOptions:方法中完成。您可以检查应用是否因为通知而启动,并设置相应的viewController进行显示。

It is done in didFinishLaunchingWithOptions: method. You can check whether the app launched because of a notification and set the appropriate viewController to display.

类似于:

-(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;
}

这篇关于从推送通知推送视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆