Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open url from string in webview for iPhone

Tags:

I want to just open a url from my string my string is already having url I just want to show in UIWebView

myString=http://maps.google.com/maps?zoom=8&sensor=false&lci=transit&layer=traffic&saddr=1.31224,103.865&daddr=1.310664,103.857132

NSString *urlString = [myString absoluteString];
NSString *urlAddress =myString;// 
NSURL *url = [NSURL URLWithString:urlString ];

NSLog(@" url is %@",url); its null 
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];


NSLog(@" url req  is %@",url);
//Load the request in the UIWebView.
[webe loadRequest:requestObj];

I am getting this error

se&lci=transit&layer=traffic&saddr=1.31224,103.865&daddr=1.310664,103.857132
2010-08-02 13:20:08.253 Wat2Eat[5332:207] *** -[NSCFString absoluteString]: unrecognized selector sent to instance 0x1ac570
2010-08-02 13:20:08.267 Wat2Eat[5332:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString absoluteString]: unrecognized selector sent to instance 0x1ac570'
2010-08-02 13:20:08.283 Wat2Eat[5332:207] Stack: (
like image 266
ram Avatar asked Aug 02 '10 05:08

ram


People also ask

Does WebView work on iOS?

WKWebView replaces the UIWebView class in iOS 8 and later, and it replaces the WebView class in macOS 10.10 and later. Embed a WKWebView object programmatically into your view hierarchy, or add it using Interface Builder.

Which browser is used in iOS WebView?

Which browser iOS use in their webview? Safari browser installed in iOS & webview browser (if safari) are same or there are difference?

What is UIWebView in iOS?

What is UIWebView? UIWebView is a deprecated iOS user interface control in Apple's UIKit framework. It loads HTML files and web content into an app view, rendering them as they would appear in a browser window. See developer.apple.com/documentation/uikit/uiwebview.


2 Answers

Add this to your method:

    NSString *urlAddress = @"http://myurl.com";

//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//Load the request in the UIWebView.
[detailWebView loadRequest:requestObj];
like image 93
Atma Avatar answered Oct 26 '22 01:10

Atma


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSURL *websiteUrl = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
[myWebView loadRequest:urlRequest]; 
}
like image 25
Erinson Avatar answered Oct 26 '22 01:10

Erinson