Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改后更新MacOS通知中心菜单栏图标';请勿打扰';以编程方式设置_Macos_Icons_Menubar_Notificationcenter - Fatal编程技术网

更改后更新MacOS通知中心菜单栏图标';请勿打扰';以编程方式设置

更改后更新MacOS通知中心菜单栏图标';请勿打扰';以编程方式设置,macos,icons,menubar,notificationcenter,Macos,Icons,Menubar,Notificationcenter,我已经在Mac上编程实现了“启用/禁用MacOS通知中心的请勿打扰”功能 环境:macOS Mojave 10.14.6,Xcode 11.3.1 这是我的代码(目标C): 当我将“是”传递给该方法时,菜单栏上的图标变暗,单击后,我可以看到请勿打扰开关打开 当我向该方法传递“否”时,请勿打扰开关关闭,但变暗的图标不会恢复到正常状态 一个小瑕疵,如果有人能帮我修复,那就太完美了 - (void)setDoNotDisturbEnabled:(BOOL)flag{ CFStringRef

我已经在Mac上编程实现了“启用/禁用MacOS通知中心的请勿打扰”功能

环境:macOS Mojave 10.14.6,Xcode 11.3.1

这是我的代码(目标C):

当我将“是”传递给该方法时,菜单栏上的图标变暗,单击后,我可以看到请勿打扰开关打开

当我向该方法传递“否”时,请勿打扰开关关闭,但变暗的图标不会恢复到正常状态

一个小瑕疵,如果有人能帮我修复,那就太完美了


- (void)setDoNotDisturbEnabled:(BOOL)flag{
    CFStringRef appID = CFSTR("com.apple.notificationcenterui");
    
    CFPreferencesSetValue(CFSTR("doNotDisturb"),
                          (__bridge CFPropertyListRef)([NSNumber numberWithBool:flag]),
                          appID,
                          kCFPreferencesCurrentUser,
                          kCFPreferencesCurrentHost);
    
    if(flag){
        CFPreferencesSetValue(CFSTR("doNotDisturbDate"),
                              (__bridge CFPropertyListRef)([NSDate dateWithTimeIntervalSinceNow:0]),
                              appID,
                              kCFPreferencesCurrentUser,
                              kCFPreferencesCurrentHost);
    }else{
        CFPreferencesSetValue(CFSTR("doNotDisturbDate"),
                              NULL,
                              appID,
                              kCFPreferencesCurrentUser,
                              kCFPreferencesCurrentHost);
    }
    
    [[[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.notificationcenterui"] firstObject] forceTerminate];
}