NSData & NSURL – url with space having problem

Use: stringByAddingPercentEscapesUsingEncoding: Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string. -(NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding A representation of the receiver using encoding to determine the percent escapes necessary to convert the receiver into a legal URL string. Returns nil if encoding … Read more

Convert String to NSURL is return nil in swift

As suggested by the Martin R, I see THIS post and I converted that objective-c code to swift and I got this code: var url : NSString = “https://maps.googleapis.com/maps/api/distancematrix/json?origins=\(self.latitud‌​e),\(self.longitude)&destinations=\(self.stringForDistance)&language=en-US” var urlStr : NSString = url.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! var searchURL : NSURL = NSURL(string: urlStr)! println(searchURL) and this is working correctly. For swift 3.0: let url : NSString … Read more

How to use openURL for making a phone call in Swift?

I am pretty sure you want: UIApplication.sharedApplication().openURL(NSURL(string: “tel://9809088798”)!) (note that in your question text, you put tel//:, not tel://). NSURL’s string init expects a well-formed URL. It will not turn a bunch of numbers into a telephone number. You sometimes see phone-number detection in UIWebView, but that’s being done at a higher level than NSURL. … Read more

Replace occurrences of space in URL

The correct format for replacing space from url is : Swift 4.2 , Swift 5 var urlString = originalString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) Swift 4 var urlString = originalString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) Objective C NSString *urlString;//your url string. urlString = [originalUrl stringByReplacingOccurrencesOfString:@” ” withString:@”%20″]; or urlString = [originalUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; iOS 9 and later urlString = [originalUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

Objective-C: How to add query parameter to NSURL?

Since iOS 7 you can use NSURLComponents that is very simple to use. Take a look on these examples: Example 1 NSString *urlString = @”https://mail.google.com/mail/u/0/?shva=1#inbox”; NSURLComponents *components = [[NSURLComponents alloc] initWithString:urlString]; NSLog(@”%@ – %@ – %@ – %@”, components.scheme, components.host, components.query, components.fragment); Example 2 NSString *urlString = @”https://mail.google.com/mail/u/0/?shva=1#inbox”; NSURLComponents *components = [[NSURLComponents alloc] initWithString:urlString]; if … Read more

NSURL path vs absoluteString

Question 1: What is the actual difference between these methods? Let’s analyze this writing 6 lines of code – 3 for a local and 3 for http URL – and playing around with them a little bit. Let’s create an NSURL using the file:// scheme. If you ask yourself why there are 3 / after … Read more