如何在用户在“弹出”菜单中执行操作时打开新的Safari选项卡。 ?

时间:2018-01-25 15:28:53

标签: objective-c macos cocoa safari-extension

我已经创建了Safari扩展[通过本地方式创建]

enter image description here

其中,我开始在Safari浏览器中打开新标签

Click on Button : Open New Tab

单击按钮:

- (IBAction)btnClick:(id)sender {


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

}];}

我得到 self.sfWindow :null

1 个答案:

答案 0 :(得分:0)

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]];