A pretty simple question i am sure, but i don't know how to go about doing such a thing. At current i $post variable 1 and variable 2 to the server and return some son data this is pretty slow but it worked, then it all went down hill when i started to have execution issues on the server side. Rented server so can't change php.ini file. So i have came up with this idea as a work around.
Would it be possible to direct to my download source, if the link itself contained variables collected from my label.text rather than writing each individual link out for each group (127 to be precise). For instance variable1 would equal "hell" and variable to would equal "red" therefore my NSURL would point to www.test.com/hell/red.php
Is this possible or is there some other way of doing this?
NSURL *url = [NSURL URLWithString:#"http://www.test.com/$variable1/$variable2.php"];
So now i know that this is possible, is some form or way, how can i resolve the following errors that i am receiving? For what i understand i simply can't have a / between the two variables and i can't have the .json file extension included on the end of the url.
If you require anymore code don't hesitate to ask.
Thank you very much in advance for any help!
The string you are creating the NSURL with is a normal NSString. To use variables in a NSString, you can use:
[NSString stringWithFormat:#"http://www.test.com/%#/%#.php", variable1, variable2];
%# is a placeholder for a string. variable1 and variable2 must be NSStrings
The line that creates could look like this:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.test.com/%#/%#.php", variable1, variable2]];
Or:
NSString * urlString = [NSString stringWithFormat:#"http://www.test.com/%#/%#.php", variable1, variable2];
NSURL * url = [NSURL URLWithString:urlString];
You can try this one:
NSString *urlString = [NSString stringWithFormat:#"http://www.test.com/%#/%#.php", var1, var2];
NSURL *url = [NSURL URLWithString:urlString];
I am stuck in a very obvious method of NSURL class URLWithString I am passing a string and while creating URL it returns nil, my string is perfect. When ever I uses same string in browser then it is working fine. I am using following method to convert NSString to NSURL:
NSURL *url = [NSURL URLWithString:urlString];
//urlString is my perfect string
I have also tried to encode my string first by using following
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// using this line my output string when I log url is "url%10%10%10%10%10%10..."
%10 becomes the suffix of my url with around 100+ repetition.
If any one has idea what %10 is or what can be done to overcome this problem.
here is my urlString:
Use below code to resolve your problem.
NSString *str = msgDetail[#"thumbnail"];
NSString* webStringURL = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
NSURL* url = [NSURL URLWithString:webStringURL];
yes what was wrong in my string were many unidentified characters due to copying from internet site, if anyone of the reader facing this issue can copy and paste your string as see the count. And confirm.
Thanks
Try below solution
NSURL *url = [NSURL URLWithString:[urlString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Check it..!
I want to use customize QR, I have a url, if I pass that url in browser they display a QR in browser and if i use this url in our code they return null, this is my url that I want to use in our code:
http://api.qrcode.unitag.fr/api?t_pwd=degraded&setting={"EYES":{"EYE_TYPE":"LLLeft","COLOR_EHD":"8a9935","COLOR_IHD":"8a9935","COLOR_EBG":"71801f","COLOR_IBG":"71801f"},"BODY_TYPE":2,"LAYOUT":{"COLORBG":"ffffff","GRADIENT_TYPE":"HORI","COLOR1":"afc928","COLOR2":"d7eb67","FORCE_SHADOW":"L","COLOR_SHADOW":"b6b8a7"}}&data={"DATA":{"MESSAGE":"Hello","PHONE":"0505050505"},"TYPE":"smsto"}
This is my code for encode that url
NSString *unescaped = #"http://api.qrcode.unitag.fr/api?t_pwd=degraded&setting={%22EYES%22:{%22EYE_TYPE%22:%22LLLeft%22,%22COLOR_EHD%22:%228a9935%22,%22COLOR_IHD%22:%228a9935%22,%22COLOR_EBG%22:%2271801f%22,%22COLOR_IBG%22:%2271801f%22},%22BODY_TYPE%22:2,%22LAYOUT%22:{%22COLORBG%22:%22ffffff%22,%22GRADIENT_TYPE%22:%22HORI%22,%22COLOR1%22:%22afc928%22,%22COLOR2%22:%22d7eb67%22,%22FORCE_SHADOW%22:%22L%22,%22COLOR_SHADOW%22:%22b6b8a7%22}}&data={%22DATA%22:{%22MESSAGE%22:%22Hello%22,%22PHONE%22:%220505050505%22},%22TYPE%22:%22smsto%22}";
NSString *escapedString = [unescaped stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSLog(#"escapedString: %#", escapedString);
NSURL *url = [NSURL URLWithString:escapedString];
[img_barcode setImageWithURL:url placeholderImage:nil];
i am using above code but i am not getting image, please tell me about this process how i can get image successfully.
The URL in your code is already escaped. By escaping it again, you destroy it.
Either start with a properly URL escaped string and don't do any further processing on it:
NSString *escaped = #"http://api.qrcode.unitag.fr/api?t_pwd=degraded&setting={%22EYES%22{%22EYE_TYPE%22:%22LLLeft%22,%22COLOR_EHD%22:%228a9935%22,%22COLOR_IHD%22:%228a9935%22,%22COLOR_EBG%22:%2271801f%22,%22COLOR_IBG%22:%2271801f%22},%22BODY_TYPE%22:2,%22LAYOUT%22{%22COLORBG%22:%22ffffff%22,%22GRADIENT_TYPE%22:%22HORI%22,%22COLOR1%22:%22afc928%22,%22COLOR2%22:%22d7eb67%22,%22FORCE_SHADOW%22:%22L%22,%22COLOR_SHADOW%22:%22b6b8a7%22}}&data={%22DATA%22{%22MESSAGE%22:%22Hello%22,%22PHONE%22:%220505050505%22},%22TYPE%22:%22smsto%22}";
Or start with the base url and the parameters, then URL escape each parameter value and combine it into the complete URL:
Base URL: http://api.qrcode.unitag.fr/api
t_pwd: degraded
setting: {"EYES":{"EYE_TYPE":"LLLeft","COLOR_EHD":"8a9935","COLOR_IHD":"8a9935","COLOR_EBG":"71801f","COLOR_IBG":"71801f"},"BODY_TYPE":2,"LAYOUT":{"COLORBG":"ffffff","GRADIENT_TYPE":"HORI","COLOR1":"afc928","COLOR2":"d7eb67","FORCE_SHADOW":"L","COLOR_SHADOW":"b6b8a7"}}
data: {"DATA":{"MESSAGE":"Hello","PHONE":"0505050505"},"TYPE":"smsto"}
So the easiest solution is probably to remove the code lines that run the URL encoding.
Finally i solved the problem thank every one.
that was my url:
http://api.qrcode.unitag.fr/api?t_pwd=degraded&setting={"EYES":{"EYE_TYPE":"LLLeft","COLOR_EHD":"8a9935","COLOR_IHD":"8a9935","COLOR_EBG":"71801f","COLOR_IBG":"71801f"},"BODY_TYPE":2,"LAYOUT":{"COLORBG":"ffffff","GRADIENT_TYPE":"HORI","COLOR1":"afc928","COLOR2":"d7eb67","FORCE_SHADOW":"L","COLOR_SHADOW":"b6b8a7"}}&data={"DATA":{"MESSAGE":"Hello","PHONE":"0505050505"},"TYPE":"smsto"}
and i just added back slash before the (") (") like this \"EYES\", and after that i use this line of code:
NSString *escapedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSURL * imageURL = [NSURL URLWithString:escapedUrlString];
[img_barcode setImageWithURL:imageURL placeholderImage:nil];
and my problem is solved.
Im using QLPreviewController to view word, excel,pdf etc. The problem is the file is in the server so I need to download it from a certain URL.
I'm using this code:
NSURL *dLurl = [NSURL URLWithString:[NSString stringWithFormat:#"%#",DLPathStr]];
NSData *data = [NSData dataWithContentsOfURL:dLurl];
for downloading files, It works for the PDF file but in the word and excel files it doesn't work I'm not able to download anything.
I fixed it by using this code it doesn't download anything because the URL is wrong because it contains spaces.
NSString *str = [DLPathStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *dLurl = [NSURL URLWithString:[NSString stringWithFormat:#"%#",str]];
Suppose you have a URL that looks like http://localhost:5867 and your wanted to append '/something' to the url. How do I append segments to this URL?
I am trying this:
//_baseURL is NSURL* and documentid is NSString*
NSURL* url = [_baseURL URLByAppendingPathComponent:documentid];
Oddly.. xcode(4.6.2) will not output the resulting URL to console.
NSLog(#"%#", [url absoluteString]);//nothing output
Thanks!
Edit
I am working in a workspace. The code that I am debugging is a static lib which is in the workspace. Could this be the culprit of all this weirdness??
Fixed
I think the reason I was having problems was because my workspace was not configured correctly and I was actually executing an older version of my static lib. This explains why I wasn't getting NSLog'ing and why the result were unexpected. I found this post which helped me understand the workspace and how to configure it for a static library. Thanks a lot for everyone's time!
There is a class message,
+ (id)URLWithString:(NSString *)URLString relativeToURL:(NSURL *)baseURL
So,
NSURL *base = [NSURL URLWithString: #"http://localhost:5867"];
NSURL *child = [NSURL URLWithString: #"something" relativeToURL:base];
NSURL *base = [NSURL URLWithString:#"http://localhost:5867"];
NSURL *url = [base URLByAppendingPathComponent:#"something"];
NSLog(#"%#", [url absoluteString]);
This works for me and prints http://localhost:5867/something, so check your variables (maybe one of them is nil or an empty string?).