gpt4 book ai didi

objective-c - 从推送通知推送 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:15:51 24 4
gpt4 key购买 nike

我成功收到了 iOS 5 的通知。我希望能够在用户滑动或点击通知中心的推送通知时将他们转到特定 View 。

我希望用户去反对我的应用程序的开始的 View Controller ( View )是“groceryStoreViewController”。我读到这是在 didFinishLaunchingWithOptions 或 didReceiveRemoteNotification 中完成的,但我不确定。

如果有人知道如何做到这一点,我将不胜感激,因为这确实是一场斗争。

谢谢

编辑

所以问题是我希望在用户点击通知时打开特定的 View Controller ,但我也希望保留 UITabBar。我没有成功地做到这一点,这与我显示我相信的 subview 有关。请告诉我您的想法,非常感谢。

- (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 以显示。

类似于:

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

关于objective-c - 从推送通知推送 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10345624/

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