Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Properly Decoding string url for casting in NSURL

I am making player which going to support Google DFP adserver. The Ad-server has a VAST link which is XML type and contains media-file, track links, clickLink etc...

The clickLinks includes a redirecting url to the original url which I could not properly decode.

The link looks like: https://pubads.g.doubleclick.net/aclk?sa=L&ai=B2JSpRFcKVq_SAsifbr-gqPAE9-CGpQcAAAAQASCPsd4lOABY37Owp4gCYJn-noa4IboBCzYyNHgzNTJfeG1syAEF2gEFaHR0cDqpArGOjXR685U-wAIC4AIA6gIULzEzMTMwMjQwNy9Vem1hbl9Ea3n4AvTRHpADhAeYA4QHqAMB0ASQTuAEAZAGAaAGI9gHAQ&num=0&cid=5Ggrgwo88gHDUD7JBb6uTLxZ&sig=AOD64_0xhsqN4jSnVOZ-eKo9KCVTet61iQ&client=ca-pub-3069068742246799&adurl=http://dkykartal.com/%3Futm_source%3DUzmanTV%26utm_medium%3DVideo_PreRoll%26utm_content%3DDKY_Kartal%26utm_campaign%3DDKY_Kartal_IBillBoard

I tried to decode by using stringByAddingPercentEscapesUsingEncoding and then encode again but NSURL seems to be broken.

Original VastURL is:

https://pubads.g.doubleclick.net/gampad/ads?sz=624x352&iu=/131302407/Uzman_Dky&impl=s&gdfp_req=1&env=vp&output=xml_vast2&unviewed_position_start=1&url=[referrer_url]&description_url=[description_url]&correlator=1443516172

How can properly cast this to an NSURL?

like image 233
Onder OZCAN Avatar asked Sep 30 '15 11:09

Onder OZCAN


1 Answers

Read your question again, carefully. You say you want to decode the URL and call a method that's called

stringByAddingPercentEscapesUsingEncoding
        ^^^^^^

Try using stringByRemovingPercentEncoding. This should decode your URL.

To the other question, how to "cast" it to NSURL: Casting means you are forcing the debugger to treat a variable like a specific type. Meaning you cannot cast an object and turn it into an instance of another type.

You have to create an instance of NSURL using a string:

NSURL *URL = [NSURL URLWithString:[URLString stringByRemovingPercentEncoding]];

like image 128
Julian F. Weinert Avatar answered Oct 18 '22 12:10

Julian F. Weinert