Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.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 NSWorkspace设置图标未更新El Capitan上的应用程序图标_Macos_Osx Elcapitan - Fatal编程技术网

Macos NSWorkspace设置图标未更新El Capitan上的应用程序图标

Macos NSWorkspace设置图标未更新El Capitan上的应用程序图标,macos,osx-elcapitan,Macos,Osx Elcapitan,我正在使用NSWorkSpaceSetIcon:forFile:options:更改应用程序图标。在约塞米蒂,它运行良好。然而,El Capitan上的应用程序图标没有更新。您并不孤单。 尝试先设置零图标,然后再设置您的图标: [[NSWorkspace sharedWorkspace] setIcon:nil forFile:path options:0] [[NSWorkspace sharedWorkspace] setIcon:image forFile:path options:0];

我正在使用NSWorkSpace
SetIcon:forFile:options:
更改应用程序图标。在约塞米蒂,它运行良好。然而,El Capitan上的应用程序图标没有更新。

您并不孤单。 尝试先设置零图标,然后再设置您的图标:

[[NSWorkspace sharedWorkspace] setIcon:nil forFile:path options:0]
[[NSWorkspace sharedWorkspace] setIcon:image forFile:path options:0];

我在OSx 10.14.6上也遇到了同样的问题。我使用的变通方法是,在创建文件后延迟一段时间后设置图标。立即设置图标有时有效,有时即使返回成功也无法刷新

    auto nspath = [NSString stringWithUTF8String:path.c_str()];
    auto nsdata = [contents dataUsingEncoding:NSUTF8StringEncoding];
    [[NSFileManager defaultManager] removeItemAtPath:nspath error:nil];
    auto ret = [[NSFileManager defaultManager] createFileAtPath:nspath contents:nsdata attributes:nil];
    // hide the extension of the file after creation.
    if (ret) {
        [[NSFileManager defaultManager] setAttributes:@{NSFileExtensionHidden: @true} ofItemAtPath:nspath error:nil];
        // set the icon, after a delay. Bug in OSx, the icon is not reflected sometimes despite YES return
        // if it is set immediately after creating the file.
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
            auto img = [NSImage imageNamed:@"Icon"];
            [[NSWorkspace sharedWorkspace] setIcon:img forFile:nspath options:0];
        });
    }

你好@EdiZ。上述解决方案不起作用。有没有其他方法可以做到这一点?