iPhone: Open a url Programmatically

前端 未结 4 743
情话喂你
情话喂你 2020-12-28 14:42

I am new to iPhone. I want to open an url in my application. How can I do this task? Please suggest me and provide some useful link.

4条回答
  •  Happy的楠姐
    2020-12-28 15:23

    If you would like to open and just get the data from the URL, you could use NSString:

    NSString *ans = [NSString stringWithContentsOfURL:url];
    

    If what you are trying to get is an XML from a URL, you can directly use NSXMLParser:

    NSURL *url = [[NSURL alloc] initWithString:urlstr];
    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    // parse here
    [parser release];
    [url release];
    

    On the other hand, if by opening you mean, open a URl in an embedded browser, you could use UIWebView class.

提交回复
热议问题