Objective c 使用NSWorkspace在浏览器中打开多个URL

Objective c 使用NSWorkspace在浏览器中打开多个URL,objective-c,xcode,macos,cocoa,nsworkspace,Objective C,Xcode,Macos,Cocoa,Nsworkspace,在我的应用程序中,我想在web浏览器中打开多个URL 我是这样做的: int options = NSWorkspaceLaunchWithoutActivation | NSWorkspaceLaunchWithErrorPresentation; [[NSWorkspace sharedWorkspace] openURLs: urls withAppBundleIdentifier: @"com.apple.safari"

在我的应用程序中,我想在web浏览器中打开多个URL

我是这样做的:

int options = NSWorkspaceLaunchWithoutActivation | NSWorkspaceLaunchWithErrorPresentation;

[[NSWorkspace sharedWorkspace] openURLs: urls
                withAppBundleIdentifier: @"com.apple.safari"
                                options: options
         additionalEventParamDescriptor: nil
                      launchIdentifiers: nil];
Safari现在一次只能打开六个URL,当我使用
NSWorkspaceLaunchRorPresentation
时,我会收到以下错误消息:

无法打开应用程序“Safari”,因为它没有响应


现在,当我将bundle标识符设置为
com.google.Chrome
时,情况更糟,只打开了4个选项卡。Firefox(
org.mozilla.Firefox
)也会打开6个选项卡。

一个简单的方法可以绕过您描述的限制,即使用等待或睡眠功能。它应该允许您根据自己的决定打开任意多个URL:

-(void)openURLs {

for (int i = 0; i <= 18; i++) { // open 18 URLS for this example

        NSString *url = @"http://google.com";
        [self openURL:url];

        [NSThread sleepForTimeInterval:0.2f]; // wait .02 second
    }
}

- (void)openURL:(NSString *)url {

int options = NSWorkspaceLaunchWithoutActivation | NSWorkspaceLaunchWithErrorPresentation;

    NSArray *urls = [NSArray arrayWithObject:[NSURL URLWithString:url]];

    [[NSWorkspace sharedWorkspace] openURLs: urls
                    withAppBundleIdentifier: @"com.apple.safari"
                                    options: options
             additionalEventParamDescriptor: nil
                          launchIdentifiers: nil];
}
-(无效)OpenURL{

对于(int i=0;i)你想打开多少个URL?嗯,肯定有六个以上。可能有十个,可能有三十个。我认识的一些人总是打开大量的选项卡,所以我认为六个是非常有限的。没错,可能是一次性方法限制了它;试着在六次迭代后做一个
sleep(1);
if(i==6)sleep(1)
刚刚尝试过,它很管用-尽管看起来很粗糙。把它放在调度队列中是看不见的-甚至没有注意到
睡眠(1)
好的,谢谢你的研究。我会研究这个问题。如果你把你的方法作为一个答案,我很乐意接受。我很乐意。我也会把一个更好的例子放在一起:)