I have a URL which is in a string: http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1
I am trying to convert that string to NSURL.
I've tried several things, which are:
NSString *encodedString = [#"http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:encodedString];
When I follow the URL object with a breakpoint it assigns 0 => false.
What should I do to convert that string to NSURL?
The parameters in your given URL string are already URL encoded. So:
NSString *string = #"http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1";
NSURL *url = [NSURL URLWithString:string];
// url is not nil
Related
how to convert Nsurl Domain to my country domain
Example :
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
How can get some thing like http://www.google.com.eg
it can detect my zone and change it with my domain zone, if website support multi zones domain.
If there isn't a path in the url just append .eg to the end of the string.
NSString *newCountryString = [[url absoluteString] stringByAppendingString:#".eg"];
NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];
If the url has a path do this:
NSString *host = [url host];
NSString *domain = [[host componentsSeparatedByString:#"."] lastObject];
NSString *newCountryString = [[url absoluteString] stringByReplacingOccurrencesOfString:domain withString:[domain stringByAppendingString:#".eg"]];
NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];
i am NewBie in iOS Development. I want to Decode my NSURL With Pagination Here my Url Like as
http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0
And i Decode this URL Like as
NSURL *urls = [NSURL URLWithString:#"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0"];
NSString *urlString = [urls absoluteString];
NSLog(#"UrlString %#",urlString);
NSURL * url=[NSURL URLWithString:urlString];
But it Give me Only 0 Page Url i want to Like as make my url as
NSURL *urls=[NSURL URLWithString:#"My Url &page=%d",pagenum];
Here i want at place of My Url as Decoding of my Original Url If it is Possible then Please Give me Solution for it.
you are doing it in wrong way.
this is the right way
NSString *urlString = #"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=";
NSURL *targetURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#%d",urlString,pageNumber]];
NSLog(#"targetURL is : %#",targetURL);
Hope this will help you..
NSString *str=#"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0";
NSString *result =[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urls = [NSURL URLWithString:result] ;
I want to parse the location of my Documents Directory to NSUrl from NSString I have.
when my console NSLog(stringURL)
i get: "/var/mobile/Applications/2B35D06D-6E4A-40F2-833E-28463A946834/Library/Application Support/MyAppDirectory" as an output.
but when I do
NSURL* url = [NSURL URLWithString:stringUrl];
and NSLog(url) i get (null) as an output.
WHat am I doing wrong here?
From the apple documentation "An NSURL object initialized with URLString. If the URL string was malformed or nil, returns nil." Your stringURL isn't a correct formed url. For reference: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/clm/NSURL/URLWithString:
What you actually want to use is: fileURLWithPath: isDirectory: instead.
NSURL *url = [NSURL fileURLWithString:[stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] isDirectory:YES];
NSLog(#"%#", url);
How about:
NSURL* url = [NSURL fileURLWithString:stringUrl];
// ^^^^
Use fileURLWithPath instead (since you are passing a file path):
NSURL* url = [NSURL fileURLWithPath:stringUrl];
I am trying to place strings inside my NSURL, I have tried most suggestions but all seem to fail, i'm trying to find a easy way to do it instead of having to use some long request with long code. I'm wondering is there anything small here i'm forgetting?
NSString *lat = #"53.350628";
NSString *lng = #"-6.254997";
NSURL *blogURL = [NSURL URLWithString:#"http://url.com/jsontest.php?lat=%#&lng=%#&max=5", lat, lng];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
Thanks,
Curtis
+[NSURL URLWithStirng:] does not take a format string and a variable argument list. It just takes a string, so you should use something like +[NSString stringWithFormat:] first before passing it to URLWithString, like this:
NSURL *blogURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://url.com/jsontest.php?lat=%#&lng=%#&max=5", lat, lng]];
Format the string, than add that to the NSURL
NSString *lat = #"53.350628";
NSString *lng = #"-6.254997";
//Format String
NSString *urlString = [NSString stringWithFormat:#"http://url.com/jsontest.php?lat=%#&lng=%#&max=5", lat, lng];
NSURL *blogURL = [NSURL URLWithString:urlString];
NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];
I am generating a URL as given by string parameters but url gives null value.
For generating URL I have implemented the following code .
NSURL *url = [[NSURL alloc] init];
NSString *strURL = #"ftp://Administrat:ABC(R%-#TRDOP#xx.xx.xx.xx/arrows.png";
url = [NSURL URLWithString:[NSString stringWithString:strURL]];
NSLog(#"URL :: %#",url);
Thanks
You need to escape the special characters in the url query string.
Use:
NSString *strURL = #"ftp://www.jerox.com/Administrator:#123#TRDOP#%$/arrows.png";
strURL =[strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:strURL];
NSLog(#"URL :: %#",url);
Also I need to mention some mistakes in your code:
No need to allocate and init the NSURL object, because you are again assigning another object to that pointer
No need of using stringWithString: there
Make use of the following code.
NSString *sURL = #"ftp://www.jerox.com/Administrator:#123#TRDOP#%$/arrows.png";
NSURL *url = [[NSURL alloc] initWithString:[sURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(#"URL :: %#",url);
From your posted code sample, here is the problem:
NSString *strURL = #"ftp://Administrat:ABC(R%-#TRDOP#xx.xx.xx.xx/arrows.png";
Look carefully at the authority component (username, password and host). An # symbol is used in URLs to separate username & password from the host. Because your password contains an # character, it must be percent escaped. The percent encoding of # is %40, giving you instead the code:
NSString *strURL = #"ftp://Administrat:ABC(R%-%40TRDOP#xx.xx.xx.xx/arrows.png";
You really ought to be escaping other URL-specific characters in there too, like the lone % symbol.