ingame html link to a web browser
by Eyal Erez · in iTorque 2D · 01/29/2009 (3:20 pm) · 15 replies
I think I've seen a thread for it before, but I can't find it. The search doesn't seem to work either.
Anyway.... do you guys know how to have a link in your game that will open a web-browser?
Anyway.... do you guys know how to have a link in your game that will open a web-browser?
#2
01/29/2009 (4:01 pm)
it works. Thanks Conor.
#3
sounds like setUsesPhysics() but I don't think so this time :)
01/29/2009 (6:16 pm)
it only works on the Mac but not on the device.sounds like setUsesPhysics() but I don't think so this time :)
#4
01/29/2009 (6:27 pm)
In the normal version of Torque, that calls a platform function to open a browser. Have you tried in the simulator?
#5
It seems the console function calls this function. I don't quite understand how it works on the Mac.
bool Platform::openWebBrowser( const char* webAddress )
{
return false;//use renderHTML view?
}
01/29/2009 (6:38 pm)
I just did. no luck.It seems the console function calls this function. I don't quite understand how it works on the Mac.
bool Platform::openWebBrowser( const char* webAddress )
{
return false;//use renderHTML view?
}
#6
01/29/2009 (9:39 pm)
hehe looks like that hole hasn't been plugged yet then.
#7
01/29/2009 (10:09 pm)
But it does work on the Mac. how?
#8
01/30/2009 (5:42 am)
likely the mac platform XCode code has handling code behind it but the iphone one not or is not plugged in
#9
So theoretically , we could just add the UIApplication::openURL() to a console command and use that , right?
The problem is that I don't know how to do it. I've tried adding it to the existing ConsoleFunction(gotoWebPage) ,but i get and error. UIApplication is not declared. Obviously, I don't know what I'm doing. Here's what I did.
ConsoleFunction( gotoWebPage, void, 2, 2, "( address ) - Open a URL in the user's favorite web browser." )
{
argc;
char* protocolSep = dStrstr(argv[1],"://");
if( protocolSep != NULL )
{
Platform::openWebBrowser(argv[1]);
UIApplication::openURL(argv[1]); /////////// That's my addition :)
return;
}........
Here's the apple docs.
http://developer.apple.com/iphone/library/featuredarticles/iPhoneURLScheme_Reference/iPhoneURLScheme_Reference.pdf
01/30/2009 (9:27 am)
So I've ventured out to the actual iPhone docs (way out of my league) and found that there is a native iPhone OS method that's called openURL() . it's part of the UIApplication classSo theoretically , we could just add the UIApplication::openURL() to a console command and use that , right?
The problem is that I don't know how to do it. I've tried adding it to the existing ConsoleFunction(gotoWebPage) ,but i get and error. UIApplication is not declared. Obviously, I don't know what I'm doing. Here's what I did.
ConsoleFunction( gotoWebPage, void, 2, 2, "( address ) - Open a URL in the user's favorite web browser." )
{
argc;
char* protocolSep = dStrstr(argv[1],"://");
if( protocolSep != NULL )
{
Platform::openWebBrowser(argv[1]);
UIApplication::openURL(argv[1]); /////////// That's my addition :)
return;
}........
Here's the apple docs.
http://developer.apple.com/iphone/library/featuredarticles/iPhoneURLScheme_Reference/iPhoneURLScheme_Reference.pdf
#10
in source/platformiPhoneiPhoneWindow.mm replace the empty function with this one
NOTE: this will kill your application and launch Safari.
Ideally, you could make a new GUI or script call that would implement a UIWebView, essentially embedding a web page into your app, but this will work for a web link.
01/30/2009 (5:13 pm)
Here's the fix:in source/platformiPhoneiPhoneWindow.mm replace the empty function with this one
bool Platform::openWebBrowser( const char* webAddress )
{
NSString *string = [[NSString alloc] initWithUTF8String: webAddress];
NSURL *url = [[NSURL alloc] initWithString: string];
bool ret =[platState.application openURL: url];
[string release];
[url release];
return ret;
}NOTE: this will kill your application and launch Safari.
Ideally, you could make a new GUI or script call that would implement a UIWebView, essentially embedding a web page into your app, but this will work for a web link.
#11
I see now that I wasn't even close to get it to work :)
As far as killing the game, that's fine. It's actually exactly what I need.
01/30/2009 (5:48 pm)
Thanks Mat. works like a charm. I see now that I wasn't even close to get it to work :)
As far as killing the game, that's fine. It's actually exactly what I need.
#12
01/31/2009 (12:52 pm)
Thanks for contributing that fix
#13
07/22/2009 (1:05 pm)
Will this be implemented in 1.2.1?
#14
07/22/2009 (4:30 pm)
Isn't this already present in 1.2.0?
#15
07/22/2009 (7:03 pm)
I dunno, I never used it. Just glad to see there's an option, one way or another.
Conor O'Kane
cokane.com
gotoWebPage("url");