getHostApplicationWithCompletionHandler: returns nil

Hi there,


I have found that the +[SFSafariApplication getHostApplicationWithCompletionHandler:] message pretty often returns (more precisely, of course, calls the completion handler with) a nil. Actually it looks like

- upon the extension launch it keeps returning nil ...

- ... until the first message from an injected JS is received, or the toolbar button is clicked, or something like that

- then it for awhile returns Safari; but in a short moment, it gets back to nil.


To add insult to injury, the handler is even declared as nonnull 🙂


The test code is trivial, inside of a Safari App Extension:


@interface SafariExtensionHandler:SFSafariExtensionHandler @end
@implementation SafariExtensionHandler
+(void)load {
    NSLog(@"launched");
    [self checkSignature];
}
+(void)checkSignature {
    [SFSafariApplication getHostApplicationWithCompletionHandler:^(NSRunningApplication * _Nonnull host) {
        NSLog(@"host: %@",host);
        [self performSelector:_cmd withObject:nil afterDelay:2];
    }];
}
... ...


The logs look like NULL, NULL, NULL ... until a script sends a message or so, then I am getting Safari for awhile, but after a moment, again NULL, NULL, NULL...


Might this be my fault? Or is that a documented behaviour whose documentation I have missed somewhere?


Thanks for any insight,

OC

Replies

That is very strange! Would it be possible to attach a sample app to a radar on bugreport.apple.com? I've never seen that issue with getHostApplication, but I've never tried calling it from +load.


Also, thanks for all of your help in the forums, I've enjoyed reading your responses and they've been very helpful!

Thanks!


I'll prepare a simple test application and post a radar soon as I can, hopefully at the start of the next week.