From my Objective C iPhone app, I want a user to click on a "Register" for account button and then open up a registration page on my website. What is the code on the iPhone to open up a website in response to a user action?
+1
A:
Create a UIButton and assign the action to a method like this:
- (IBAction)register:(id)sender {
//you'll want to subclass UIViewController
SomeViewController *webViewController = [[SomeViewController alloc]init];
[self presentModalViewController:webViewController animated:YES];
[webViewController release];
}
Your SomeViewController will have a webview that load's your register page. Then in your "SomeViewController"'s viewDidLoad, do something like this:
- (void)viewDidLoad
{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mysite.com/register"]];
//this is a webview that you either created in -loadView or IB
[self.webView loadRequest:request];
}
christo16
2010-03-23 15:49:51
I also found a quicker way to load the website: UIApplication *app = [UIApplication sharedApplication];[app openURL:[[NSURL alloc] initWithString: @"http://maps.google.com/maps?g=London"]];
MikeN
2010-03-23 15:51:51
That way works, however it makes your user leave your app. I don't know about you but I hate it when an app quits for something that it can do why still running. They might decide it's too much trouble to register for you app. Running it in a WebView is good UX.
christo16
2010-03-23 15:56:06