(Tutorial Ios) Menampilkan Webview Di Ios


Komponen untuk menampilkan halaman web di aplikasi iOS ialah UIWebView. UIWebView dipakai untuk embed konten web ke dalam aplikasi iOS. Selain menampilkan halaman web, UIWebView juga sanggup memuat document menyerupai html, doc, dan lain-lain. Untuk lebih jelasnya sanggup dilihat di dokumentasi apple https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/index.html


Mari kita coba menciptakan webview di iOS.

Pertama buat project gres dengan nama MyWebView


Masuk ke storyboard. Drag and drop komponen Web View ke layar ViewController.


Atur contraints web view dengan mengklik pin dibawah, kemudian add 4 constraints. Hal ini bertujuan biar tampilan web view sanggup multilayout di semua device iphone.


Reference UIWebView dengan klik dan tahan tombol control kemudian drag ke ViewController.h


Buat IBOutlet untuk UIWebView dengan nama webView



Berikut cara mereference IBOutlet :
Ctrl + Drag


Lengkapi ViewController.m berikut

#import "ViewController.h"  @interface ViewController ()  @end  @implementation ViewController  - (void)viewDidLoad {     [super viewDidLoad];     // Do any additional setup after loading the view, typically from a nib.          NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://m.kwikku.com"]];          [self.webView loadRequest:request]; }  - (void)didReceiveMemoryWarning {     [super didReceiveMemoryWarning];     // Dispose of any resources that can be recreated. }  - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(nonnull NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {          NSLog(@"Loading : %@", request.URL.absoluteString);          return YES; }  - (void)webViewDidStartLoad: (UIWebView *)webView{      }  - (void)webViewDidFinishLoad: (UIWebView *)webView{      }  - (void)webView: (UIWebView *)webView didFailLoadWithError:(nullable NSError *)error{     NSLog(@"Error : %@", [error debugDescription]); } @end 


Kemudian edit info.list sebagai berikut biar mengabaikan secure HTTPS (mulai dari iOS 9), untuk lebih jelasnya baca artikel ini http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/




Running project maka akhirnya akan menyerupai ini


Source code sanggup di liat di https://github.com/andronut/MyWebView

Sekian dan Terima Kasih

Happy Coding :)

Comments

Popular posts from this blog

Implementasi Basis Data

(Tutorial Ios) Custom Uitableviewcell In Uitableview

(Tutorial Android) Image Loader Using Glide