Objective-C (iOS): ブラウザを開く

OpenURLViewController

Objective-C: OpenURLViewController.h

#import <UIKit/UIKit.h>

@interface OpenURLViewController : UIViewController

@end

Objective-C: OpenURLViewController.m

#import "OpenURLViewController.h"

@interface OpenURLViewController ()

@end

@implementation OpenURLViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(50, 50, 150, 50);
    [button setTitle:@"snippets.feb19.jp" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonWasTapped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)buttonWasTapped:(UIButton *)button
{
    NSURL *url = [NSURL URLWithString:@"http://snippets.feb19.jp"];
    [[UIApplication sharedApplication] openURL:url];
}

@end