2011-05-06 61 views
0

所以,當你點擊接收推送通知視圖時,應用程序打開它呈現視圖推新的控制器與有關通知的細節我想要做的是。我正在使用UITabBarController和UINavigationControllers。任何幫助將不勝感激,我試過尋找,但我似乎無法找到任何指向正確方向的東西。低於當前代碼:如何在應用程序關閉時打開推送通知時推送新視圖?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; 

[application setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 

tabBarController = [[UITabBarController alloc] init]; 

controller = [[controller alloc] init]; 
UINavigationController *controller1 = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease]; 
controller1.tabBarItem.image = [UIImage imageNamed:@"icon_news.png"]; 
[controller setTitle:@"View"]; 
[controller release]; 

controller = [[controller alloc] init]; 
UINavigationController *controller2 = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease]; 
controller2.tabBarItem.image = [UIImage imageNamed:@"icon_news.png"]; 
[controller setTitle:@"View"]; 
[controller release]; 

controller = [[controller alloc] init]; 
UINavigationController *controller3 = [[[UINavigationController alloc] initWithRootViewController:controller3] autorelease]; 
controller3.tabBarItem.image = [UIImage imageNamed:@"icon_news.png"]; 
[controller setTitle:@"View"]; 
[controller release]; 

controller = [[controller alloc] init]; 
UINavigationController *controller4 = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease]; 
controller4.tabBarItem.image = [UIImage imageNamed:@"icon_news.png"]; 
[controller setTitle:@"View"]; 
[controller release]; 

controller = [[controller alloc] init]; 
UINavigationController *controller5 = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease]; 
controller5.tabBarItem.image = [UIImage imageNamed:@"icon_news.png"]; 
[controller setTitle:@"View"]; 
[controller release]; 

tabBarController.viewControllers = [NSArray arrayWithObjects:controller1, controller2, controller3, controller4, controller5, nil]; 

[window addSubview:tabBarController.view]; 

[window makeKeyAndVisible]; 

launchDefault = YES; 
//[self performSelector:@selector(handlePostLaunch) withObject:nil afterDelay:0]; 

// Push Notification info 

NSDictionary *apns = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 

NSString *result = [[[apns valueForKey:@"aps"] valueForKey:@"alert"] valueForKey:@"loc-args"]; 

NSString *playerID = [NSString stringWithFormat:@"%@", result]; 

playerID = [[playerID componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@""]; 

playerID = [playerID stringByReplacingOccurrencesOfString:@" " withString:@""]; 

playerID = [playerID stringByReplacingOccurrencesOfString:@"(" withString:@""]; 

playerID = [playerID stringByReplacingOccurrencesOfString:@")" withString:@""]; 

NSLog(@"Player ID: %@", playerID); 

if (![playerID isEqualToString:@"null"]) { 
    if (!detailViewController) { 
     detailViewController = [[PlayerDetailViewController alloc] init]; 
    } 

    NSManagedObjectContext *moc = [[AppController sharedAppController] managedObjectContext]; 

    NSFetchRequest *req = [[NSFetchRequest alloc] init]; 

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Players" 
               inManagedObjectContext:moc]; 
    [req setEntity:entity]; 

    NSPredicate *pre = [NSPredicate predicateWithFormat:@"playerID=%@", playerID]; 
    [req setPredicate:pre]; 

    NSError *error; 
    NSArray *list = [moc executeFetchRequest:req error:&error]; 

    [req release]; 

    Players *player = [list lastObject]; 

    [detailViewController setPlayer:player]; 

    //Want to Push view here 

    [detailViewController release]; 

    detailViewController = nil; 
} 

return YES; 

}

回答

0

如果申請被通知啓動,然後它會出現在關鍵UIApplicationLaunchOptionsRemoteNotificationKey下的應用程序委託的application:didFinishLaunchingWithOptions: launchOptions字典,裏面有所有的通知有信息(JSON轉換爲NSDictionary我相信)。

編輯:

得到了問題錯了,我認爲你在尋找什麼僅僅是指向當前選定的導航控制器。如果您查詢[tabbarcontroller selectedViewController],則會得到該結果,該結果返回可見導航控制器。然後只需將新創建的控制器推到該導航控制器的堆棧頂部。

+0

我正確地獲得通知信息,我有什麼用自動推送通知的應用程序中的詳細信息視圖的問題。對不起,如果我的問題措辭不佳。 – nlutterman 2011-05-06 21:27:55

+0

編輯我的答案,我的錯誤,並沒有完全解決問題。 – 2011-05-06 21:40:37

+0

我都試過[[[tabBarController selectedViewController] navigationController] pushViewController:detailViewController動畫:YES];和[[tabBarController selectedViewController] presentModalViewController:detailViewController animated:YES];但是它們都在int main()函數中結束了一個SIGKILL。我是否應該如何將視圖推向堆棧?我認爲pushViewcontroller是我正在尋找。 – nlutterman 2011-05-06 22:12:12

相關問題