Cocoa Touch library with UIApplication and UIWebView

260 Views Asked by At

WebView google site is not loaded in this scenario

enter image description here

While we tried to use , its get loaded...

enter image description here

Can anyone guide me how to make the first code to be worked inside cocoa touch library project

3

There are 3 best solutions below

0
Gowtham On BEST ANSWER

Use delegates to achieve webview from static library to application

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    // UIApplication * app = [UIApplication sharedApplication];
    UIWebView *web=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    web.layer.borderWidth = 1;
    web.layer.borderColor = [[UIColor redColor] CGColor];
   // NSURLRequest * req = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"https://www.yahoo.com"]];

  [web loadRequest:req];
 [self.adView addSubview:web];

Concentrate on adView ... here you will get stuck...

1
Reinier Melian On

Use this code to add the UIWebView to App key Window, your issue was that maybe where you are using your code the self.view is nil, I suppose

UIApplication * app = [UIApplication sharedApplication];
UIWebView* web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, app.keyWindow.frame.size.width, app.keyWindow.frame.size.height)];
web.layer.borderWidth = 1;
web.layer.borderColor = [[UIColor redColor] CGColor];
NSURLRequest * req = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"https://www.w3schools.com"]];
[web loadRequest:req];
[app.keyWindow addSubview:web];

Hope this helps, for me work as should

0
Moorthy On

try this code...

[[UIApplication sharedApplication] setStatusBarHidden:YES];
 UIWebView *web=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

web.layer.borderWidth = 1;
web.layer.borderColor = [[UIColor redColor] CGColor];

[web loadRequest:req]; [self.adView addSubview:web];