Nitin
Nitin

Reputation: 63

How to remove a specific remote notification from the notification area

I would like to search for a particular push notification and remove it from the notification area. I want a code which looks something like this, except that it should work for remote notifications and not local notifications. Thanks in advance.

for (UILocalNotification *lNotification in [[UIApplication sharedApplication] scheduledLocalNotifications])
{
    if (![[userRecord valueForKey:@"User"] isEqualToString:[userInfo objectForKey:@"User"]])
    {
        [[UIApplication sharedApplication] cancelLocalNotification:lNotification];

    }
}

Upvotes: 1

Views: 85

Answers (2)

baydi
baydi

Reputation: 1003

In

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
if ([[userInfo objectForKey:@"User"] isEqualToString:@"Your user"])
{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];

      //Do Nothing
      return;
 }
else
{
//process according to need
}
}

As Remote notification is sended from server so it can only be control at receiving end or from server end.I hope it will help.

Upvotes: 1

katleta3000
katleta3000

Reputation: 2494

If I understand you correct - you want to skip some remote notifications on your client. You can't do it that way. Your remote notifications are sent from apple server (usually through your server) and delivered to iOs system, then it will deliver to your app on iPhone or iWatch. In app you can use:

@available(iOS 8.0, *)
public func registerForRemoteNotifications()

@available(iOS 3.0, *)
public func unregisterForRemoteNotifications()

@available(iOS 8.0, *)
public func registerUserNotificationSettings(notificationSettings: UIUserNotificationSettings)

@available(iOS 8.0, *)
public func currentUserNotificationSettings() -> UIUserNotificationSettings?

You should make your own logic of sending remote pushes from your own server.

Upvotes: 0

Related Questions