DarkRise
DarkRise

Reputation: 1

How do you use UIKit to watch for clipboard changes in a Mac Catalyst console app in Objective-C?

I'm trying to write a console app that uses UIKit that watches for clipboard changes. Here is the code so far:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface TestClass : NSObject
- (void) pasteboardChanged:(NSNotification *) notification;
@end


@implementation TestClass
- (void) dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}
- (id) init {
    self = [super init];
    if (!self) return nil;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pasteboardChanged:) name:UIPasteboardChangedNotification object:nil];

    return self;
    
}
- (void) pasteboardChanged:(NSNotification *) notification {
    printf("2\n");
}

@end


int main(){
printf("1\n");
 TestClass* test = [[TestClass alloc] init];
 printf("2\n");
 [[NSRunLoop currentRunLoop] run];
printf("3\n");
 /*
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
dispatch_async(queue, ^{
     TestClass* test = [[TestClass alloc] init];
    // Perform async operation
    // Call your method/function here
    // Example:
  });
[NSThread sleepForTimeInterval:6000.0f];
*/
}

I compiled it with /usr/bin/clang test.m -F /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/iOSSupport/System/Library/Frameworks -framework UIKit -target arm64-apple-ios13.4-macabi -framework Foundation. It runs, but it seems that the selector does not fire (eg, copying things do not fire the selector). Is there something I'm doing incorrectly?

Upvotes: 0

Views: 21

Answers (0)

Related Questions