开发者

Using SBApplication to open a URL in Safari?

开发者 https://www.devze.com 2023-02-15 17:06 出处:网络
I\'m trying to use SBApplication to tell a couple of browsers (Safari and Chrome) to open a given URL.However, the apps just treat it like a file url.Here\'s the pseudo/JSTalk code I\'m using:

I'm trying to use SBApplication to tell a couple of browsers (Safari and Chrome) to open a given URL. However, the apps just treat it like a file url. Here's the pseudo/JSTalk code I'm using:

var safari = [SBApplication applicationWithBundleIdentifier:@"com.apple.Safari"];
var url = [NSURL URLWithString:@"http://apple.com/"];
[safari open:url]; // results in opening "file:///http/::apple.com:"

Any hints? Making a Safari.h file with sdp ( sdef /Applications/Saf开发者_Python百科ari.app | sdp -fh --basename "Safari" ) doesn't really help much to see what I can do.


Just read that you wish to open an URL using multiple browsers. Thus, my answer isn't of help here:

I'd propose to ask NSWorkspace to open the URL:

// make an URL
NSURL *someUrl = [NSURL URLWithString:@"http://my.server.vom/" ];

if ([[NSWorkspace sharedWorkspace] openURL:someURL]) {
   NSLog(@"Fine. URL opened.");
} else {
   // shouldn't happen
}

Regarding your problem: Did you try to pass a string to Safari, not an NSURL?

0

精彩评论

暂无评论...
验证码 换一张
取 消