환경
- macOS High Sierra Version 10.13.4
- Xcode Version 9.0 ((A235)
프로젝트 생성
Xcode 툴을 사용하여 앱 개발을 위한 새로운 프로젝트를 생성한다.
1. 프로젝트 템플릿을 iOS > Application > Single View App 를 선택
2. 프로젝트 이름을 기입하고 Next 버튼을 클릭한다.
3. 마지막으로 프로젝트를 생성할 저장소를 선택하고 생성(Create) 버튼을 클릭하면 프로젝트가 생성된다.
WebView 만들기
1. 생성된 프로젝트 화면에서 Main.storyboard 파일을 클릭한다.
2. 우측 하단의 Object Library 영역에서 WebView 선택하고 화면으로 Drag&Drop 한다. 화면의 영역에 맞게 WebView 상자를 크기를 조절한다.
3. ViewController.h 파일을 더블 클릭하여 새로운 창에서 파일을 연다.
4. WebVew 를 클릭하여 선택하고 우클릭하여 보여지는 Web View 메뉴에서 New Referencing Outlet 클릭한 상태로 ViewController.h 창으로 드레그 한다.
이때 보여지는 창에 이름을 입력하고 Connect 버튼을 클릭하며 WebView 가 ViewController 에 삽입된다.
ViewController.h
#import@interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UIWebView *webView; @end
기존 ViewController.m 파일에 아래와 같이 viewDidAppear 함수를 추가한다.
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidAppear:(BOOL)animated{
NSString *url = @"https://m.daum.net" ;
NSURLRequest *request = [NSURLRequest requestWithURL : [NSURL URLWithString:url]];
[_webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
애뮬레이터에서 실행하기
1. 이제 만들어진 앱이 잘 동작하는가를 확인하기 위하여 프로젝트 상단의 실행버튼을 클릭한다.
2. 화면에 보여지는 게시물을 클릭하면 아무런 반응이 없고 콘솔을 확인하면 보안 오류가 발생함을 확인할 수 있다 .
2018-04-26 13:36:01.410544+0900 MyWebViewTest[54897:13321284] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
이문제는 Info.plist 파일에 아래의 속성 값을 추가함으로 해결할 수 있다.
NSAppTransportSecurity NSAllowsArbitraryLoads NSExceptionDomains yourserver.com NSIncludesSubdomains NSTemporaryExceptionAllowsInsecureHTTPLoads NSTemporaryExceptionMinimumTLSVersion TLSv1.1











