Возникли проблемы при вызове didReceiveRemoteNotification - PullRequest
0 голосов
/ 24 января 2011

Я использую следующий код,

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  //code here to handle call
  //[[UIApplication sharedApplication] openURL:
  // [NSURL URLWithString:@"tel:1-408-555-5555"]];
  UIAlertView *alert1=[[UIAlertView alloc]initWithTitle:@"Teshjhjkhhjkhjkhjkhkjhkhkhkjhjkhjkkkjhjhhjhjkjt" message:@"Test" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
  [alert1 show];
  [alert1 release];
}

но когда приложение открыто, я вижу предупреждение, но мне нужно это предупреждение, когда я нажимаю кнопку просмотра в push-сообщении.

1 Ответ

3 голосов
/ 24 января 2011

Попробуйте реализовать в этом формате:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    application.applicationIconBadgeNumber = 0;
    self.textView.text = [userInfo description];

    // We can determine whether an application is launched as a result of the user tapping the action
    // button or whether the notification was delivered to the already-running application by examining
    // the application state.

    if (application.applicationState == UIApplicationStateActive) 
    {
        // Nothing to do if applicationState is Inactive, the iOS already displayed an alert view.
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification"
                        message:[NSString stringWithFormat:@"The application received this remote notification while it was running:\n%@",
                                 [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]
                                  delegate:self
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...