user7477041
user7477041

Reputation:

opening a received url with safari

I am receiving a url from a server request, I made a button , when pressed, safari must open and go to the link, My code below:

- (IBAction)openFeedbackWebViewPresser:(id)sender {
    NSString *feedbackUrl = self.getConfig.feedbackURL;   
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];

}

If I print the feedback url , its as below:

https://xxx.xxxxx.com/CRM/feedback#/1715171559ae979371687#/10306

I tried to use another way:

 NSURL *url = [NSURL URLWithString:feedbackUrl];
    [[UIApplication sharedApplication] openURL: url];

the url is returning nil, knowing that the feedbackUrl contains a url. Any idea whats wrong? Thanks

Upvotes: 0

Views: 152

Answers (3)

Faizan Ali
Faizan Ali

Reputation: 9

This is the code to open the link in browser, Hope this help

    - (IBAction)emailButton:(id)sender {

[[UIApplication sharedApplication]
 openURL:[NSURL URLWithString:self.emailLabel.text]];
    }

Upvotes: -1

Pooja Gupta
Pooja Gupta

Reputation: 793

This might be happening because of the special characters that must be encoded. The following encoding works for me-

NSString *feedbackUrl = [self.getConfig.feedbackURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];   
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];

Upvotes: 1

Vanita L.
Vanita L.

Reputation: 1325

Might be your string url is containing any spaces or any other special characters that must be encoded. like below

 NSString *feedbackUrl = [self.getConfig.feedbackURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];   
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];

hope it helps.!!!

Upvotes: 1

Related Questions