 |
 |
Launch an NSURL
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Just a pretty quick question. How is it possible to have NSURL objects launch with the default internet preferences. How can an NSURL object of http://www.macnn.com/ be launched in the users default web browser.
Thanks,
Dave
------------------
Think Different.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Does anybody know something about this? It would be of utmost help.
------------------
Think Different.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
Here is a code snippit from the Fire app source code (I hope it's OK to put this up here.) This method will open an URL in the default browser:
Code:
- (void)performOpenURL:(NSString *)urlString
{
const char *urlUTF8String;
long start, length;
OSStatus error;
ICInstance anInstance;
if (ICStart(&anInstance, MY_APPLICATION_SIGNATURE) != noErr)
return ;
urlUTF8String = [urlString UTF8String];
start = 0;
length = strlen(urlUTF8String);
error = ICLaunchURL(anInstance, NULL, (Ptr)urlUTF8String, length, &start, &length);
if (error != noErr) {
NSRunAlertPanel(@"ICLaunchURL returned an error while launching URL %@: 0x%x (%d)", @"Are you sure you have a default web browser set up in System Preferences/Internet?", nil, nil, nil);
}
}
Note: The function "ICLaunchURL" is a carbon function from InternetConfig.h. This means you must include the carbon libraries for this to work.
You can get the Fire source code here: http://www.epicware.com/fire.html
This is pretty much a work around. There is probably an easy way to do this in cocoa but I do not know of it. Anyhow, hope this helps.
Ryan
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
Double Post
[This message has been edited by Ryan Bates (edited 04-05-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Thank you very much for the effort. I might try this temporarily, but I'm really looking for a Cocoa solution to the problem.
Thanks,
Dave
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
There's a new method in NSWorkspace that you can only find in the Apple Kit Release documentation. It looks like it will do the job.
- (BOOL)openURL  NSURL *)url
Description: This will use a system-dependent means of displaying the given URL to the user, or return NO if NSWorkspace cannot find such a means.
Let me know if it works, I'm curious.
Ryan
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
Ahh dang, another double post. Am I good at that or what?
[This message has been edited by Ryan Bates (edited 04-05-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Thanks for finding that.
BUT when I use it the following occurs:
My application quits and the log says:
URL Box.app has exited due to signal 11 (SIGSEGV).
I have no idea what this means. Can anybody shed some light?
Dave
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Here's what the console said:
Apr 06 15:58:44 URL Box[342] LSOpenCFURLRef() returned -50 for URL (null).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Now it says:
URL Box.app has exited due to signal 10 (SIGBUS).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
I get the SIGSEGV signal 11 also when I try to use the openFile withApplication methods.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
Originally posted by davecom:
I get the SIGSEGV signal 11 also when I try to use the openFile withApplication methods.
It sounds like your NSWorkspace object isn't being initialized correctly. It should go something like this:
myWorkspace = [NSWorkspace sharedWorkspace];
Make sure you do this before calling any other workspace method. I don't know what else it could be.
Edit: Or maybe you should even make a workspace object, just call this (it was some example code on the page):
[[NSWorkspace sharedWorkspace] openURL:anURL];
Well, try both ways and see if it works.
Edit 2: Changed performOpenURL: to openURL: (sorry for all of the mistakes)
Ryan
[This message has been edited by Ryan Bates (edited 04-06-2001).]
[This message has been edited by Ryan Bates (edited 04-06-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
Thank you for you continued interst Ryan. Tried both ways, but the same error occured. If I can't get this working in a few days I'll probably just bite the bullet and use the carbon method. By the way, what headers need to be included for the carbon one to work?
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
Originally posted by davecom:
Thank you for you continued interst Ryan. Tried both ways, but the same error occured. If I can't get this working in a few days I'll probably just bite the bullet and use the carbon method. By the way, what headers need to be included for the carbon one to work?
I'm not exactly sure which headers to include. The Fire app included the entire carbon framework but you might be able to get away with just including the HIToolbox framework, or even just the InternetConfig.h file in the HIToolbox framework. Here's the code to import the different frameworks:
#import <Carbon/Carbon.h>
or
#import <HIToolbox/HIToolbox.h>
or
#import <HIToolbox/InternetConfig.h>
First try the carbon framework, then work your way down and see if anything breaks.
Ryan
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
I thought I would try the NSWorkspace out on my own, and guess what? It worked!
I created a new project; then a new controller class in IB. I linked the application delegate to the controller class, then included this code in the controller class:
Code:
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.macnn.com"]];
}
This launched Omniweb (my default browser) and loaded www.macnn.com in a new window. I'm not sure what your problem is; it could be that you are calling the NSWorkspace function in a class's initializing method? Sometimes that causes problems. If you still can't get it to work, I can send you the example over email. Let me know if you need it.
Ryan
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
I'll probably work on the carbon thing. I'm sorry but I'm working on a semi-commerical application so I can't give too many details. I'll tell you this much though. It is rather complicated in from where the URL object comes. I've narrowed down to the line causing the problem.
NSString *surl = [obutton[i] getUstring];
url = [NSURL URLWithString:surl];
[[NSWorkspace sharedWorkspace] openURL:surl];
The middle line above is the one causing the problem and I don't know why. It always just crashes the app with a Sigsegv 11 or Sigbus 10.
Thanks again for all the help!
Dave
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
All is well now!
I found a workaround using arrays to hold URLS.
Thank you so much for your help, Ryan.
Hopefully others have learned from all of this.
Dave
------------------
Think Different.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
Originally posted by davecom:
I'll probably work on the carbon thing. I'm sorry but I'm working on a semi-commerical application so I can't give too many details. I'll tell you this much though. It is rather complicated in from where the URL object comes. I've narrowed down to the line causing the problem.
NSString *surl = [obutton[i] getUstring];
url = [NSURL URLWithString:surl];
[[NSWorkspace sharedWorkspace] openURL:surl];
The middle line above is the one causing the problem and I don't know why. It always just crashes the app with a Sigsegv 11 or Sigbus 10.
Thanks again for all the help!
Dave
That's perfectly understandable if you can't give any details. There was a problem with the above code, but it was probably just a typo. You wrote "openURL:surl" instead of "openURL:url". Anyhow, I tried creating an NSString object and an NSURL object keeping the same format as yours and it worked. The only thing I can think of is that something is wrong with the surl. I really have no idea why it's not working. It's probably simple, but hard to find.
Ryan
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
Originally posted by davecom:
All is well now!
I found a workaround using arrays to hold URLS.
Thank you so much for your help, Ryan.
Hopefully others have learned from all of this. 
Dave
Wow cool. Not sure why that would make a difference, but if it works that's what counts. Glad you found it out.
Ryan
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: New York
Status:
Offline
|
|
I caught that typo earlier and fixed it, but it still didn't work. Unfortunately it really in the end had something to do with a custom button implementation that I made. Just goes to show - ya' never know!
Dave
------------------
Think Different.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|