1

I received this error from Apple at the time of publication of my application. how can I solve this problem? We found that when Dark Mode is enabled, the menu bar extra icons aren't visible. I can not find anything online to define Dark mode...

enter image description here enter image description here enter image description here

  • 1
    Please add your code as text, not as an image – Paulw11 Oct 08 '18 at 09:08
  • You seem to have dark icons in the dark appearance area of your asset. They aren't going to be visible in dark mode. You need light coloured images for dark mode – Paulw11 Oct 08 '18 at 09:15
  • @Paulw11 ok, I entered them. now at the code level what should I do? –  Oct 08 '18 at 09:16
  • Nothing. The system selects the right appearance automatically. https://developer.apple.com/documentation/appkit/images_and_pdf/providing_images_for_different_appearances – Paulw11 Oct 08 '18 at 09:16
  • 1
    You are referring to some error from Apple but haven't mentioned which. Also, I find it weird that your Xcode is in light mode but the editor has a dark scheme. Are you building on macOS 10.13? If so, [the dark mode colors and images won't work](https://stackoverflow.com/a/53482255/400056)! – DarkDust Dec 06 '18 at 13:47

1 Answers1

1

I see the term cache in your code and taking some guesses:

It looks like you are loading the images, then manipulating them and storing the manipulated images for later use. There are a number of things you need to take care of:

First of all, make sure the current appearance is set correctly when you do your image loading/manipulation. Outside of drawRect: and a few other methods, you always need to do a dance similar to this:

NSAppearance * savedAppearance = [NSAppearance currentAppearance];
[NSAppearance setCurrentAppearance:someView.effectiveAppearance];

// Do your image/color/drawing stuff.

[NSAppearance setCurrentAppearance:savedAppearance];

Be aware that the appearance is "scoped" to a specific view! You can have different appearances in the same view hierarchy.

You need to either override viewDidChangeEffectiveAppearance of your NSView or KVObserve the effectiveAppearance of a view to get notified about appearance changes and react accordingly (recreate your icons).

DarkDust
  • 90,870
  • 19
  • 190
  • 224