【问题标题】:How to hide UIAlertView when receiving Push Notification in iOS在 iOS 中接收推送通知时如何隐藏 UIAlertView
【发布时间】:2015-08-19 21:39:41
【问题描述】:

在我的 iOS 应用程序中,我想在 didreceiveRemotenotification 方法中接收 推送通知 时隐藏 UIAlertView。 应用程序委托的整个页面我没有为显示 UIAlertView 编写代码。那为什么会自动显示呢?

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
 [PFPush handlePush:userInfo]; 
if (application.applicationState == UIApplicationStateActive) { self.noti_json=[userInfo objectForKey:@"msg"]; 
[[NSNotificationCenter defaultCenter] postNotificationName:[userInfo objectForKey:@"title"] object:self];
 } } 

提前致谢。

编辑(为我的didReceiveRemoteNotification: 添加代码):

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
   [PFPush handlePush:userInfo]; 
   if (application.applicationState == UIApplicationStateActive) 
   { 
      self.noti_json=[userInfo objectForKey:@"msg"];   
      [[NSNotificationCenter defaultCenter] postNotificationName:[userInfo objectForKey:@"title"] object:self]; 
    } 
 } 

【问题讨论】:

  • 发布你的 didreceiveRemotenotification 方法实现
  • - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; if (application.applicationState == UIApplicationStateActive) { self.noti_json=[userInfo objectForKey:@"msg"]; [[NSNotificationCenter defaultCenter] postNotificationName:[userInfo objectForKey:@"title"] object:self]; } }

标签: ios hide uialertview


【解决方案1】:

如果您收到推送通知的提醒,可能是因为在您的应用设置中启用了提醒。

【讨论】:

  • 如果应用程序设置禁用通知,我将无法收到与我的应用程序相关的任何通知。我想在不显示 UIAlertview 的情况下接收通知
  • 我的代码是: - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; if (application.applicationState == UIApplicationStateActive) { self.noti_json=[userInfo objectForKey:@"msg"]; [[NSNotificationCenter defaultCenter] postNotificationName:[userInfo objectForKey:@"title"] object:self]; } }
【解决方案2】:

去掉[PFPush handlePush:userInfo];这一行

并且仅当类型不是您想要避免的类型时才显示您自己的警报。

UserInfo 必须具有某种标识符或通知类型,以便您可以相应地处理特定类型的通知。

Handle Push

编辑

或者简单地使用下面的行

if(![[userInfo objectForKey:@"type"] isEqualToString:@"typeName"]){
 [PFPush handlePush:userInfo]; 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多