objective-c - 从推送通知推送 View
<p><p>我成功收到了 iOS 5 的通知。我希望能够在用户滑动或点击通知中心的推送通知时将他们发送到特定 View 。</p>
<p>我希望用户去的 ViewController ( View )与我的应用程序的开始相反是“groceryStoreViewController”。我已经读到这是在 didFinishLaunchingWithOptions 或 didReceiveRemoteNotification 中完成的,但我不确定。</p>
<p>如果有人知道如何做到这一点,我将不胜感激,因为这确实是一场斗争。</p>
<p>谢谢</p>
<p><strong>编辑</strong></p>
<p>所以问题是我希望在用户点击通知时打开特定的 ViewController ,但我也希望 UITabBar 保留。我没有成功地做到这一点,这与我显示我相信的 subview 有关。请让我知道您的想法,非常感谢。</p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.tabBarItem = [[ init] autorelease];
exploreViewController *view1 = [ initWithNibName:@"exploreViewController" bundle:nil];
view1.title= @"Explore";
Upcoming *view2 = [ initWithNibName:@"Upcoming" bundle:nil];
view2.title = @"Upcoming";
TipsViewController *view3 = [ initWithNibName:@"TipsView" bundle:nil];
view3.title = @"Tips";
UINavigationController *nav1 = [ initWithRootViewController:view1];
UINavigationController *nav2 = [ initWithRootViewController:view2];
UINavigationController *nav3 = [ initWithRootViewController:view3];
;
;
;
self.tabBarController = [[ init] autorelease];
self.tabBarController.viewControllers = ;
self.tabBarItem = [[ init] autorelease];
;
;
;
if (launchOptions != nil)
{
NSDictionary *remoteNotif = ;
NSLog(@"Launched from push notification");
//Accept push notification when app is not open
if (remoteNotif) {
NSDictionary *alertBody = ;
self.window.rootViewController = nav2;//this is what I want displayed when tapped but also maintain tab bar controller
;
;
}
}
else {
//Go here if just loading up normally without push
;
;
}
return YES;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在 <code>didFinishLaunchingWithOptions:</code> 方法中完成。您可以检查应用程序是否因为通知而启动,并设置适当的 viewController 来显示。</p>
<p>类似:</p>
<pre><code>-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// other stuff
if (launchOptions != nil) {
NSLog(@"Launched from push notification");
NSDictionary *notification = ;
// Do something with the notification dictionary
self.myViewController = init];
} else {
self.myViewController = init];
}
self.window.rootViewController = self.myViewController;
;
return YES;
}
</code></pre></p>
<p style="font-size: 20px;">关于objective-c - 从推送通知推送 View ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/10345624/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/10345624/
</a>
</p>
页:
[1]