URLWithString: returns nil

You need to escape the non-ASCII characters in your hardcoded URL as well: //localisationName is a arbitrary string here NSString* webName = [localisationName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString* stringURL = [NSString stringWithFormat:@”http://maps.google.com/maps/geo?q=%@,Montréal,Communauté-Urbaine-de-Montréal,Québec,Canadae&output=csv&oe=utf8&sensor=false”, webName]; NSString* webStringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL* url = [NSURL URLWithString:webStringURL]; You can probably remove the escaping of the localisationName since it will be handled by … Read more

Converting URL to String and back again

In Swift 5, Swift 4 and Swift 3 To convert String to URL: URL(string: String) or, URL.init(string: “yourURLString”) And to convert URL to String: URL.absoluteString The one below converts the ‘contents’ of the url to string String(contentsOf: URL)

How do I load an HTTP URL with App Transport Security enabled in iOS 9? [duplicate]

See Apple’s Info.plist reference for full details (thanks @gnasher729). You can add exceptions for specific domains in your Info.plist: <key>NSAppTransportSecurity</key> <dict> <key>NSExceptionDomains</key> <dict> <key>testdomain.com</key> <dict> <key>NSIncludesSubdomains</key> <true/> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <true/> <key>NSExceptionMinimumTLSVersion</key> <string>TLSv1.2</string> <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key> <false/> <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <true/> <key>NSThirdPartyExceptionMinimumTLSVersion</key> <string>TLSv1.2</string> <key>NSRequiresCertificateTransparency</key> <false/> </dict> </dict> </dict> All the keys for each excepted domain are optional. The speaker … Read more

Loading/Downloading image from URL on Swift

Xcode 8 or later • Swift 3 or later Synchronously: if let filePath = Bundle.main.path(forResource: “imageName”, ofType: “jpg”), let image = UIImage(contentsOfFile: filePath) { imageView.contentMode = .scaleAspectFit imageView.image = image } Asynchronously: Create a method with a completion handler to get the image data from your url func getData(from url: URL, completion: @escaping (Data?, URLResponse?, … Read more