2012-07-19 4 views
1

나는 alertview.When로 푸시 알림을하고있는 아이폰 응용 프로그램을 가지고 내 응용 프로그램이 푸시 알림이오고 배경 상태에 있으며, 내가 그것을 클릭하거나 직접 전화를 잠금을 해제 할 때 내가 어디 forground 상태에서 왼쪽 애플 리케이션. 나는 다른보기 컨트롤러로가는보기 버튼 클릭에 대한 경고에 조치를 추가하고 있습니다. 나는 알림을 클릭하면 응용 프로그램을 입력하고 싶지 않아. 난 alertview을 보여줄 필요하고보기 버튼을 클릭하면 내가 action.Can 사람이 저를 달성하는 데 도움이 나의 할 필요가 이걸 내 코드`입니다 - 당신은 사용자에게 UIAlertView를 보여푸시 알림 알림보기 작업?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    //check application in forground or background 
    if(application.applicationState == UIApplicationStateActive) 
    { 
     //NSLog(@"FOreGround"); 
     //NSLog(@"and Showing %@",userInfo) 
    } 
    else 
    { 
     NSDictionary *curDict= [userInfo objectForKey:@"aps"]; 
     UIAlertView *connectionAlert = [[UIAlertView alloc] initWithTitle:@"app" message:[NSString stringWithFormat:@"%@",[curDict objectForKey:@"alert"]] delegate:self cancelButtonTitle:@"View" otherButtonTitles:@"Cancel",nil]; 
     [connectionAlert show]; 
     [connectionAlert release]; 
     [UIApplication sharedApplication].applicationIconBadgeNumber =[[curDict objectForKey:@"badge"] intValue]; 
    } 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
    NSLog(@"applicationWillEnterForeground"); 
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; 

    if ([title isEqualToString:@"View"]) 
    { 
     NSArray *mycontrollers = self.tabBarController.viewControllers; 
     NSLog(@"%@",mycontrollers); 
     [[mycontrollers objectAtIndex:0] popToRootViewControllerAnimated:NO]; 
     mycontrollers = nil; 
     tabBarController.selectedIndex = 0; 
    } 
} 
+0

미안하지만 당신은 더 정확한 될 수 있을까? 알림을 터치 할 때 앱에 들어가기를 원하지 않습니까? 그건 전혀 불가능합니다 ... – Yorxxx

답변

0

알림이 수신되면 didReceiveRemoteNotification : 함수가 호출되었습니다.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
    { 
     NSLog(@"userInfo :%@",userInfo); 

     NSString* msg = [userInfo valueForKey:@"aps"]; 

     if (self._VCObj.isViewLoaded && self._VCObj.view.window) { 
       // viewController is visible don't show. 
     } 
      else { // viewController is not visible 
       [[[UIAlertView alloc]initWithTitle:@"Title" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil] show]; 
      } 
     } 
    } 

See Tutorial