ios - 在调用 didReceiveRemoteNotification 时遇到问题

标签 ios objective-c push-notification apple-push-notifications

我正在使用以下代码,

- (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];
}

但是当应用程序打开时我可以看到警报,但是当我在推送消息中按下查看按钮时我想要这个警报。

最佳答案

尝试以这种格式实现:

- (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];
    }
}

关于ios - 在调用 didReceiveRemoteNotification 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4781313/

相关文章:

android - 如何从 App Center Push SDK 的用户 ID 中删除用户 ID 和/或设备 ID/信息

ios - PDF小猫类似物

ios - 视频大小调整不符合请求的大小

ios - GMSAutocompleteViewController 想要在搜索点击时获取搜索栏中的文本

ios - 与 NSURLConnection 一起使用时如何计算 MBProgressHUD 模式的进度?

ios - Firebase + auth0 身份验证

javascript - 在 Node.js 中实现通知队列

iphone - 如何将坐标从英寸转换为像素?

ios - 过滤应该警告的通知是可能的吗?

ios - WatchKit:在通知短外观和长外观中更改应用程序名称?