2011-05-06 9 views
0

그래서 내가하려고하는 것은 응용 프로그램이 열릴 때 푸시 알림을받을 때보기를 클릭하면 제시된보기에 알림과 관련된 세부 정보가있는 새 컨트롤러가 추가됩니다. UINavigationController와 함께 UITabBarController를 사용하고 있습니다. 어떤 도움을 많이 주시면 감사하겠습니다. 검색을 시도했지만 올바른 방향으로 나를 가리키는 것을 찾지 못했습니다. 아래 현재 코드 :앱이 닫히는 동안 푸시 알림을 열 때 새로운보기를 푸시하는 방법?

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

다음은 (JSON 알림이 가지고있는 모든 정보를 가지고있는 키 UIApplicationLaunchOptionsRemoteNotificationKey에서 응용 프로그램의 대리인의 application:didFinishLaunchingWithOptions: launchOptions 사전에 존재합니다 내가 믿는 NSDictionary로 변환).

편집 :

가 나는 당신이 찾고있는 것은 바로 현재 선택된 탐색 컨트롤러에 대한 포인터 생각, 질문이 잘못 얻었다. 표시되는 탐색 컨트롤러를 반환하는 [tabbarcontroller selectedViewController]을 쿼리하면 표시됩니다. 그런 다음 새로 만든 컨트롤러를 해당 탐색 컨트롤러의 스택 맨 위에 밀어 넣기 만하면됩니다.

+0

알림 정보가 올바르게 표시됩니다. 문제가있는 경우 알림 앱에서 상세보기가 자동으로 푸시됩니다. 미안 내 질문에 잘못 말한 경우. – nlutterman

+0

편집 한 나의 대답, 나의 실수는, 확실히 질문을 얻지 못했습니다. –

+0

나는 [[[tabBarController selectedViewController] navigationController] pushViewController : detailViewController animated : YES]를 시도했다. 및 [[tabBarController selectedViewController] presentModalViewController : detailViewController animated : YES]; 하지만 둘 다 int main() 함수에서 SIGKILL로 끝납니다. 뷰를 스택에 푸시해야하는 방법에 잘못된 점이 있습니까? 나는 pushViewcontroller가 내가 찾고있는 것이라고 생각했다. – nlutterman

관련 문제