How can I open a website if I use SDL and OpenGL?

Member
Posts: 249
Joined: 2008.10
Post: #1
Hi friends!

I know I may open a website (and close my app) with this line:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];

But the problem is that all my code is in C/C++, and even I don't have AppDelegate, because I'm doing a game using SDL and OpenGL (by the way, it works perfectly).
I'm really interested cause I'd like a way to open my website or itunes link from my Lite version (something similar to iShoot Lite).

I have no idea how can I implement this.

Any suggestion?
Thanks in advance.
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #2
Don't use SDL on the iPhone, use the standard OpenGL ES template in Xcode which does have an AppDelegate and use what you're used to Smile

"When you dream, there are no rules..."
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #3
riruilo Wrote:Hi friends!

I know I may open a website (and close my app) with this line:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];

But the problem is that all my code is in C/C++, and even I don't have AppDelegate, because I'm doing a game using SDL and OpenGL (by the way, it works perfectly).
I'm really interested cause I'd like a way to open my website or itunes link from my Lite version (something similar to iShoot Lite).

I have no idea how can I implement this.

Any suggestion?
Thanks in advance.


SDL_uikitappdelegate.h

Code:
/* *INDENT-OFF* */
@interface SDLUIKitDelegate:NSObject<UIApplicationDelegate> {
    UIWindow *window;
}

@property (readwrite, retain) UIWindow *window;

+(SDLUIKitDelegate *)sharedAppDelegate;

@end
/* *INDENT-ON* */
Quote this message in a reply
Member
Posts: 249
Joined: 2008.10
Post: #4
warmi Wrote:SDL_uikitappdelegate.h

Code:
/* *INDENT-OFF* */
@interface SDLUIKitDelegate:NSObject<UIApplicationDelegate> {
    UIWindow *window;
}

@property (readwrite, retain) UIWindow *window;

+(SDLUIKitDelegate *)sharedAppDelegate;

@end
/* *INDENT-ON* */

@warmi, can you explain it a litle bit more? I have no idea abot Obj-C
I guess with that code I can get the address of my app delegate, but not sure. Should I create an .m or .mm to use it?

@Taxxodium: I use SDL because I'm porting a game, and the way, SDL works very well on the iPhone.

Thanks a lot
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #5
Use [UIApplication sharedApplication]...

You can use Cocoa directly in C++ by using an ".mm" file extension or, if you're like me and like to keep them separate, make a ".m" file (call it whatever, lets say "cocoawrappers.m"). Then add something like this:

Code:
void
OpenURL(const char *url)
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
}

Then create a C header for that file "cocoawrappers.h" (or whatever) and add the prototype:

Code:
void OpenURL(const char *url);

Now you can include the header and call it like any other C function from your C/C++ code.
Quote this message in a reply
Member
Posts: 249
Joined: 2008.10
Post: #6
Thanks Frank for reply.

I'm trying to implement it, but I am not successful. Actually I have no idea about Obj-C, I think I'm going to read some tutorials...

I just added #import "cocowrappers.h" to your first piece of code and name it to cocoawrappers.m, and the second one cocoawrappers.h, I include it on my C++ code but xcode linker says "symbol not found, collect2: id returned status"

I know I'm doing something wrong, but I have no idea.

Frank, do you mean I have to use only [UIApplication sharedApplication] or should I also use warmi proposal? (SDL_uikitappdelegate.h)
Do not forget I'm using SDL.

I know this seems easy, but I'm so bad with Obj-C.

Any suggestion please?

Thanks a lot, I appreciate it a lot.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #7
riruilo Wrote:"symbol not found, collect2: id returned status"
This might be a dumb question, but did you add cocoawrappers.m to your project?

riruilo Wrote:do you mean I have to use only [UIApplication sharedApplication] or should I also use warmi proposal? (SDL_uikitappdelegate.h)
Do not forget I'm using SDL.
[UIApplication sharedApplication] is a global variable that returns the active application delegate. As long as you don't need to access any of the subclass' functions/variables you can use [UIApplication sharedApplication] and not care or worry about the actual app delegate's implementation.
Quote this message in a reply
Member
Posts: 249
Joined: 2008.10
Post: #8
Yes, I did it,

My files are:

cocoawrappers.h
void OpenURLLiteVersion();

cocoawrappers.m
#import "cocoawrappers.h"
void OpenURLLiteVersion() {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];
}


Should I include any class or interface, or those files are correct?

Thanks.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #9
Looks fine from here, though ya, you might need to import UIApplication.h in the .m file depending on how things are set up. You also might need some header guards in the header.

Also be sure to check inside your target's "Complie Sources" phase to ensure the files is actually being compiled. It's possible to add it to the project but not to the target.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  website for submitting an app Bommbomm 3 5,569 Jul 4, 2011 03:03 PM
Last Post: bdsowers
  What kind of info does certificate uploads to applet website? riruilo 1 2,525 Jan 28, 2009 09:37 PM
Last Post: AnotherJake