4

I have a push notifications with badge, sounds and alerts enabled. If the program is not running - everything is fine. But when the program is running - I need to block all sounds, alerts and badges that are not generated by program, because I have a live connection to my server and receiving all events before APNS sends notifications to my mac device. I've found the way to hide alerts, but I couldn't find any way to take over control on dockTile's icon badge. if i do this:

-(void)application:(NSApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
  [[NSApp dockTile] setBadgeLabel:nil];
}

nothing is happened, the badge that is set by APNS still persists. I tried to KVO on badgeLabel or dockTileNumber property as shown here, but observeValueForKeyPath:ofObject:change:context: is never called. How do APNS sets the badgeLabel? Maybe I am doing something wrong and there is a correct way to disable alerts/sounds/badges when the program is running?

Community
  • 1
  • 1
Sega-Zero
  • 3,034
  • 2
  • 22
  • 46
  • right now I've found some workaround, but this looks very dirty, there have to be a better way `-(void)application:(NSApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [application dockTile].badgeLabel = @" "; [application dockTile].badgeLabel = @""; }` – Sega-Zero May 20 '14 at 23:21

1 Answers1

1

Since i did not found any solutions to do it correctly, i will accept my workaround:

-(void)application:(NSApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    [application dockTile].badgeLabel = @" "; 
    [application dockTile].badgeLabel = @""; 
}

Alerts may be disabled via NSUserNotificationCenterDelegate delegate method userNotificationCenter:shouldPresentNotification::

-(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
{
    //apple push notification alert will contain userInfo with aps payload, so disable here
    if (notification.userInfo[@"aps"])
        return NO;

    return YES;
}

I haven't found any ways to disable sounds.

Sega-Zero
  • 3,034
  • 2
  • 22
  • 46