Search code examples
objective-cmacoscocoasafari-extension

How to open new Safari Tab when user perform actions in Popover menu . ?


i've Created Safari Extension [Created via native way]

enter image description here

in which , i'm stucked in to open new tab into safari browser

Click on Button : Open New Tab

onClick of the Button :

- (IBAction)btnClick:(id)sender {


[self.sfWindow openTabWithURL:[NSURL URLWithString:@"https://www.facebook.com"] makeActiveIfPossible:true completionHandler:^(SFSafariTab * _Nullable tab) {
    NSLog(@"Naman Vaishnav");

}];}

In which I'm getting self.sfWindow : null


Solution

  • CFURLRef httpURL = CFURLCreateWithString(kCFAllocatorDefault, CFSTR("http://"), NULL);
    NSLog(@"%@", LSCopyDefaultApplicationURLForURL(httpURL, kLSRolesAll, nil));
    
    NSString *strDefaultBrowser = [NSString stringWithFormat:@"%@",LSCopyDefaultApplicationURLForURL(httpURL, kLSRolesAll, nil)];
    
    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:websiteName]];