Post

Replies

Boosts

Views

Activity

NSAlert accessory view
I need to add an accessory view with a text field to an NSAlert. This works as expected but as my app comes in different languages, the alert looks a bit different depending on the language used: So I wonder how I can make the text field automatically use the full width of the alert window. I tried to call the alert's layout method and then resize the text field but this seems not work in all cases. Any help would be highly appreciated. Thanks!
0
0
199
Oct ’24
NSAttributedString draw in rect
I need to draw an attributed string into a given rectangle. The string's height should be the same as the rectangle's height. This should work with any font a user chooses. To make it a bit more complicated, the string should also fill the rect if it consists only of uppercase characters or only of lowercase characters. I am using NSLayoutManager to find the "best" font size for the selected font and the given recht and it works quite good with some fonts but with others it doesn't. Seems like the computed font size is always a bit too small and for some fonts it seems like the baseline must be corrected. Unfortunately I didn't find a way to calculate a baseline offset that really works with any font. I attached some sample images showing the issue. Just posting this to make sure I am not running in the complete wrong direction. Any help would be highly appreciated. Thanks!
13
0
731
Aug ’24
User defaults not updating
In an app I bound an NSArrayController's content array to a NSUserDefaultsController like this: [_arrayController bind:NSContentArrayBinding toObject:_userDefaultsController withKeyPath:@"values.anArrayOfDictionaries" options:nil]; This works as expected. If I add objects to the array controller or remove them, the user defaults are updated accordingly. But if I modify the content array in any other way, this seems not to trigger KVO and the user defaults are not updated. I tried various combinations of: [self.arrayController willChangeValueForKey:...]; ... [self.arrayController didChangeValueForKey:...]; but it did not work. So I ended up doing the following: [_userDefaults setObject:[_arrayController content] forKey:anArrayOfDictionaries]; This works but I am pretty sure there must be a better way to get the changes I made to the array controller's content array into the user defaults. Thanks in advance for your help. Regards, Marc
3
0
391
Aug ’24
Launch constraints disappear
I use launch constraints in a project. If I archive the project and save a copy of the app locally, everything works as expected but if I choose "Direct Distribution" and submit the app to Apple for notarization, the notarized app does not contain any launch constraints. What are I am doing wrong? Thanks.
6
0
726
Jul ’24
Launch constraints to prevent an agent from being launched manually by a user?
One of our apps contains an agent that is launched at login using a plist in /Library/LaunchAgents. Now the question came up if I can make sure this agent is only launched by the system and cannot be launched by a user or another application. I wonder if this can be done using launch constraints. I played a bit with responsible application constraints but I couldn't make it work. Either the agent didn't launch at all or it could also be launched by just double-clicking on it in Finder. I wonder whether this is even possible. Thanks.
6
0
664
Jul ’24
Check if a binary or script is executable
In one of our apps (not sandboxed) the user can choose a file that matches one of the following UTTypes using an NSOpenPanel: UTTypeApplicationBundle UTTypeUnixExecutable UTTypeShellScript The selected file will then be launched under certain circumstances. This works pretty well but from time to time we see internal support tickets where people complain because the selected file is not executed. This only affects files of type UTTypeUnixExecutable and UTTypeShellScript for which the Unix permissions are incorrect. They are therefore not executable. I would now like to check in the app whether the selected file is executable. With app bundles this works without any problems with isExecutableFileAtPath:, but with the other file types this does not work. What is the recommended way to test this for the other files? Is there a better way than checking the POSIX permissions (and owner/group)? Thanks.
3
0
528
Jul ’24
Responsible process launch constraint not working as expected
I wrote a daemon that is launched from the following plist in /Library/LaunchDaemons: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>MachServices</key> <dict> <key>com.mycompany.daemon.xpc</key> <true/> </dict> <key>Label</key> <string>com.mycompany.daemon</string> <key>Program</key> <string>/Applications/MyApp.app/Contents/MacOS/MyDaemon</string> <key>AssociatedBundleIdentifiers</key> <string>com.mycompany.myapp</string> <key>SpawnConstraint</key> <dict> <key>team-identifier</key> <string>XXXXXXXXX</string> <key>signing-identifier</key> <string>com.mycompany.myapp</string> </dict> </dict> </plist> No I want to make sure the daemon can only be launched via xpc by MyApp and I embedded the following responsible process plist into the daemon: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>team-identifier</key> <string>XXXXXXXXX</string> <key>signing-identifier</key> <string>com.mycompany.myapp</string> </dict> </plist> But as soon as the plist is embedded, macOS refuses to launch the daemon because of a launch constraint violation. As I read in the documentation, the process opening and xpc connection is the responsible process. So what I am doing wrong? Thanks.
3
0
554
Jul ’24