1
votes

I am trying to open a url in iPhone default browser I did this. The code is actually supposed to get the url from an object based on a selected item in tableview

BlogPost *blogPost = [self.blogPosts objectAtIndex:indexPath.row];
UIApplication *application = [UIApplication sharedApplication];
[application openURL:blogPost.url];

When I run the app i get the error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString scheme]: unrecognized selector sent to instance 0x7febb263ba30'

I then set an Exception break point, the app crashes at the third line of code displaying the error. What should I do?

1
[[application openURL : blogPost.rl] stringvalue] you have to cast it into string.ios developer
@Chandra But blogPost.url in not a NSString?Lorenzo
blogPost.url seems to be a NSString rather than the expected NSURLvadian
@Israel can you debug your code? After the first line is correct the content of blogPost?Lorenzo

1 Answers

2
votes

Try like this

[application openURL:[NSURL URLWithString:@"http://www.google.com"]];

Make sure

blogPost.url is a NSUrl

Note: if blogPost.url is NSString type

[application openURL:[NSURL URLWithString:blogPost.url]];

The crash report clearly says that you are trying to pass NSString type value instead of passing NSUrl type value. That is type mismatch of argument blogPost.url