Error opening url in Safari

I created my application. I need to open the url in iPhone, view the safari directly.

My code is as follows:

        NSString *email = [NSString stringWithFormat:@"http://itunes.apple.com/us/album/music/id186152317?i=186153149&uo=4"];
         email = [email stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
         NSURL *url = [NSURL URLWithString:email];
         if (![[UIApplication sharedApplication] openURL:url])
         NSLog(@"%@%@",@"Failed to open url:",[url description]);
         [super viewDidLoad];

But my problem is that Safari opens. But the url is not opening. It shows an error. Error

Cannot open the page. Safari cannot open the page because the address is invalid.

But the url opens in the browser.

Does anyone know a solution to open this url in Safari on iPhone using Objective-C?

+3
source share
5 answers

You can use http://itunes.apple.com/linkmaker/ to get the exact link. Hope helps

+1
source

Change the encoding to " NSUTF8StringEncoding"

0

, Safari Mac ...

url http://itunes.apple.com/us/album/music/id186152317, , iPhone.

0

Your problem is that you should not be the URL encoding of the whole URL. You should encode only the keys and values ​​of each pair in the query string. In other words, URL-encoded code: i, 186153149, uoand 4. Nothing more. (And technically, you don’t even need to encode them, because they are all in a set of ASCII alphanumeric characters that do not need to be encoded)

0
source

Source: https://habr.com/ru/post/1782739/


All Articles