2014-05-20 1 views
3

배지, 소리 및 알림이 포함 된 푸시 알림을 사용할 수 있습니다. 프로그램이 실행 중이 아니면 모든 것이 정상입니다. 그러나 프로그램 인 경우 프로그램에서 생성되지 않은 모든 소리, 경고 및 배지를 차단해야합니다. APNS가 내 Mac 장치에 알림을 보내기 전에 서버에 실시간으로 연결되어 있고 모든 이벤트를 받기 때문에 차단해야합니다. 경고를 숨기는 방법을 찾았지만 dockTile 아이콘 배지를 제어 할 수있는 방법을 찾지 못했습니다. 내가이 할 경우 :내 코드가 아닌 [NSApp dockTile] badgeLabel 값을 설정하지 않으려면 어떻게해야하나요?

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

아무 일도하지, APNS에 의해 설정되는 배지는 여전히 지속. badbeLabel 또는 dockTileNumber 속성에 KVO를 시도한 결과 here이 표시되었지만 observeValueForKeyPath : ofObject : change : context :는 호출되지 않았습니다. APNS가 badgeLabel을 어떻게 설정합니까? 어쩌면 내가 뭔가 잘못하고 있고 프로그램이 실행 중일 때 경고음/소리/배지를 비활성화하는 올바른 방법이 있습니까?

+0

지금 내가 몇 가지 해결 방법을 발견했습니다, 그러나 이것은 아주 더러운 보이는, 더 나은 방법이있을가 '- (무효) 응용 프로그램 : (NSApplication *) 응용 프로그램의 didReceiveRemoteNotification : (NSDictionary와 *) 사용자 정보 { [ 응용 프로그램 dockTile] .badgeLabel = @ ""; [application dockTile] .badgeLabel = @ "" "; }' –

답변

1

은 내가 내 해결 방법을 받아 들일 것, 그것을 정확하게 할 어떤 해결책을 발견하지 않았기 때문에 :

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

경고 NSUserNotificationCenterDelegate 대리자 메서드 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의 천국 소리를 끄는 방법을 찾지 못했습니다.

관련 문제