-2

What the heck am I missing here??? I keep getting

No visible @interface for 'UIApplication' declares the selector 'openUrl:'

#import "ViewController.h"

@interface ViewController ()
@property (strong, readwrite, nonatomic) IBOutlet UIWebView *webView;

@end

@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
www.delegate = self;
[www loadRequest:[NSURLRequest
                  requestWithURL:[NSURL      URLWithString:@"http://www.google.com"]]];
}

- (BOOL) webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
 navigationType:(UIWebViewNavigationType)navigationType
{

if ( navigationType == UIWebViewNavigationTypeLinkClicked ) {
    NSLog(@"%@", [[request URL] absoluteString] );


    [[UIApplication sharedApplication] openUrl:[[request URL]         absoluteString]];
}

return YES;
}



@end
nhgrif
  • 61,578
  • 25
  • 134
  • 173
Harvey Dent
  • 11
  • 1
  • 1

2 Answers2

0

Presumably, the error message is actually specifying not that there is no method at all called openURL:, but that there is not method on UIApplication called openURL: which takes an NSString argument, as you are attempting to pass in here.

The following should work:

[[UIApplication sharedApplication] openURL:[request URL]];

As you can see from the documentation, openURL: takes an NSURL argument and not an NSString.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
  • 1
    You need to pay attention to spelling and case. All of your answer mentions `openURL:` except the code you say _should_ work is `openUrl:`. – rmaddy Aug 21 '16 at 15:30
  • Fixed, thanks. The dangers of copy-pasta programming apply to SO too! – nhgrif Aug 21 '16 at 15:36
0

Why do you get this error and did you call wrongly?

Yes your code is not correct.

[[UIApplication sharedApplication] openUrl:[[request URL]         absoluteString]];

The above code shows incorrect syntax as you called absoluteString.So it definitely shows error.

There is no such argument 'NSString' which taken by openURL

So what you want to do is you can call string url with URLWithString if your absoluteString has URL and uyou can directly call that URL

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"https://www.google.co.in/#q=STACKOVERFLOW+IOS+QUESTIONS"]];
user3182143
  • 9,459
  • 3
  • 32
  • 39