NSApplication's openURLs delegate method not getting called

Hi, I am trying to invoke this NSApplicationDelegate callback from my Mac app, but it's not getting called:

- (void)application:(NSApplication *)application openURLs:(NSArray<NSURL *> *)urls

I have registered the URL scheme in my Info.plist:

<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLName</key>
			<string>com.my.testapp</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>mytestapp</string>
			</array>
		</dict>
	</array>

Now I use a 2nd Mac app to test this out, by invoking the following code:

if let url = URL(string: "mytestapp://") {
            NSWorkspace.shared.open(url)
        }

This causes my first app to come to the foreground, and the "applicationDidBecomeActive:(NSNotification *)notification" method gets called, but the "application:(NSApplication *)application openURLs:(NSArray<NSURL *> *)urls" method mentioned above doesn't get invoked, which is what I want.

Any ideas about why that might be the case?

Accepted Answer

Soon after typing this out, I found the culprit! The Mac app was using the Dropbox v2 SDK, which requires the app to register for Apple 'events', using this:

[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
                                                       andSelector:@selector(handleAppleEvent:withReplyEvent:)
                                                     forEventClass:kInternetEventClass
                                                        andEventID:kAEGetURL];

With this handler in place, the actual NSApplication "application openURLs" method doesn't get called. Removing this 'event handler' gets it working again (or can handler the event in this 'handleAppleEvent' method, like this:

- (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
    NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
}

Just putting it out there in case someone is stuck on this in the future.

NSApplication's openURLs delegate method not getting called
 
 
Q