Skip to content

Commit 1129d6b

Browse files
committed
fix(clipboard): detect macOS 15.4+ via NSProcessInfo, not respondsToSelector
The respondsToSelector: probe for -accessBehavior / -setAccessBehavior: was returning NO on macOS Tahoe under the unsigned JVM, causing the example's Privacy card to claim the API was unsupported even though the runtime does expose it. Switch to [NSProcessInfo isOperatingSystemAtLeastVersion:] for the support flag — more reliable, independent of ObjC metadata visibility. The selector probes on get/set remain as a safety net.
1 parent 60635b0 commit 1129d6b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

clipboard-macos/src/main/native/macos/nucleus_clipboard.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
static JavaVM *g_jvm = NULL;
2020

21+
static BOOL isMacOS_15_4_or_later(void) {
22+
NSOperatingSystemVersion v = { .majorVersion = 15, .minorVersion = 4, .patchVersion = 0 };
23+
return [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:v];
24+
}
25+
2126
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
2227
(void)reserved;
2328
g_jvm = vm;
@@ -348,9 +353,6 @@ static jobjectArray toJStringArray(JNIEnv *env, NSArray<NSString *> *items) {
348353
JNIEnv *env, jclass cls) {
349354
(void)env; (void)cls;
350355
@autoreleasepool {
351-
NSPasteboard *pb = [NSPasteboard generalPasteboard];
352-
BOOL hasGetter = [pb respondsToSelector:NSSelectorFromString(@"accessBehavior")];
353-
BOOL hasSetter = [pb respondsToSelector:NSSelectorFromString(@"setAccessBehavior:")];
354-
return (hasGetter && hasSetter) ? JNI_TRUE : JNI_FALSE;
356+
return isMacOS_15_4_or_later() ? JNI_TRUE : JNI_FALSE;
355357
}
356358
}

0 commit comments

Comments
 (0)