jogi alamni
jogi alamni

Reputation: 393

how to open url on button click in iPhone

I have a url which i have in NSString urlone which is coming from xml. but i run application it gives excess bad error

  // urlone contains  http://www.forasinvest.com/v2/index.php

  NSString*myurl=urlone;
  NSURL *url = [NSURL URLWithString:myurl];
  [[UIApplication sharedApplication] openURL:url];

Upvotes: 38

Views: 39527

Answers (3)

Shubham JAin
Shubham JAin

Reputation: 613

NSString *pURL = @"xyz.cpm";

if( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:pURL]])
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:pURL]];

Upvotes: 15

shanezzar
shanezzar

Reputation: 1170

The most updated code till date, working with iOS 11.3 and if you're not looking for a deprecated warning, use this single line of code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"https://example.com"] options:@{} completionHandler:nil];

Upvotes: 12

Najeebullah Shah
Najeebullah Shah

Reputation: 3709

i think it should work fine, ok just copy paste the following for testing simply

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.forasinvest.com/v2/index.php"]];

Upvotes: 77

Related Questions