Is it not possible to dynamically change or constrain an NSPreferencePane's mainView size? I have looked all over and this doesn't seem to be mentioned anywhere. The most I can seemingly do is set the frame and hope the user doesn't resize the window.
class scor: NSPreferencePane {
override func mainViewDidLoad() {
mainView = NSHostingView(rootView: ContentView())
mainView.frame = NSMakeRect(0, 0, 668, 1048)
}
}
Here is a screenshot, just with a simple webview as a test, note the scrollbar:
My storyboard is just from the default prefpane Xcode template, nothing special. I looked at the header file for NSPreferencePane and came up with nothing. All I can think of is that this is impossible due to the way they are implemented? The only thing we seemingly have access to is mainView, so I can't like constrain the size of mainView to its parent, for example.
Additionally, if I make a new preference pane, and make a button or other view that I choose to resize to fill horizontally and vertically, it does that, but not really? Here is what that looks like:
The behaviour is similar to the previous preference pane, the width does adapt correctly, the height stays the same, forever.
Not that it really matters but I am using macOS 14.7.6 on an M2 air
Preference Panes
RSS for tagIntegrate your app's custom preferences into the System Preferences app using Preference Panes.
Posts under Preference Panes tag
2 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,
I try to use NSUserDefaults to share some parameter values between the container app and the system extension. I have added the App Group in Signing & Capabilities in both apps. I set it in the container app and read it in the system extension app, but the information I read from the system extension is nil. I tested that I can read the information directly from the container app. Is the system extension running in the sandbox not allowed to read other app information? But the information I see should be OK, as shown below:
The container app code is as follows:
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yourcompany.shared"];
[sharedDefaults setObject:@"Sample Data" forKey:@"SharedData"];
[sharedDefaults synchronize];
The system expansion reading code is as follows:
NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yourcompany.shared"];
NSString *data = [sharedDefaults objectForKey:@"SharedData"];
os_log_debug(logHandle, "NSUserDefaults: %{public}@", data);