Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. //
  2. // ViewController.m
  3. // TestWebView
  4. //
  5. // Created by Thieu Mao on 3/9/17.
  6. // Copyright © 2017 thieumao. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12. @property (weak, nonatomic) IBOutlet UIWebView *webView;
  13. @property (strong, nonatomic) NSURLConnection *connection;
  14. @end
  15.  
  16. @implementation ViewController
  17.  
  18.  
  19. - (void)viewDidLoad {
  20. NSLog(@"ViewController viewDidLoad");
  21. [super viewDidLoad];
  22. [self loadWebview];
  23. NSURL *url = [NSURL URLWithString:@"http://42.119.128.237/"];
  24. NSMutableURLRequest *request;
  25. request = [NSMutableURLRequest requestWithURL:url
  26. cachePolicy:NSURLRequestReloadIgnoringCacheData
  27. timeoutInterval:12];
  28. self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately: YES];
  29. }
  30. -(void)loadWebview
  31. {
  32. NSURL *url = [NSURL URLWithString:@"http://42.119.128.237/"];
  33.  
  34. NSMutableURLRequest *request;
  35. request = [NSMutableURLRequest requestWithURL:url
  36. cachePolicy:NSURLRequestReloadIgnoringCacheData
  37. timeoutInterval:12];
  38. [_webView loadRequest:request];
  39. }
  40.  
  41. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  42. {
  43.  
  44. return YES;
  45. }
  46.  
  47.  
  48. //Then
  49. - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
  50. {
  51. NSLog(@"ViewController didReceiveAuthenticationChallenge %@", challenge);
  52. NSURLCredential * cred = [NSURLCredential credentialWithUser:@"admin"
  53. password:@"test"
  54. persistence:NSURLCredentialPersistenceForSession];
  55. [[NSURLCredentialStorage sharedCredentialStorage]setCredential:cred forProtectionSpace:[challenge protectionSpace]];
  56. [self loadWebview];
  57. }
  58.  
  59. - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection
  60. {
  61. return YES;
  62. }
  63.  
  64. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement