I have been having some issues with the new swift 2.0 conversion.
I converted my app, everything seems to have worked perfectly, however, the connection to the web server completely stopped working all together.
original code:
let tempstring: String? = "\(urlBase)"
let url = NSURL(string: tempstring!.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)
var key: NSString?
key = NSString(contentsOfURL: url!, encoding: NSUTF8StringEncoding, error: nil)
temp string would end up being http://www.zephyrpanthur.com/ --other variables and subdirectories
the conversion did:
let tempstring: String? = "\(urlBase)"
let url = NSURL(string: tempstring!.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)
var error: NSError?
var key: NSString?
do {
key = try NSString(contentsOfURL: url!, encoding: NSUTF8StringEncoding)
print(key)
}
catch var error1 as NSError {
error = error1
print(error)
key = nil
}
Basically just added a try/catch, which is awesome. However, key
is always equal to nil
.
I tried lots of stuff, and eventually figured out that if I load http://www.google.com it worked and loaded the site. I tried with Yahoo, Facebook, and some other pages that are not major names and they all worked.
When I went back to zephyrpanthur.com, it stopped working. I even tried some other servers I own, like, 8bitfox.com and that also didn't work. I tried with and without www.
and with and without ssl (https/http)
Anything from my own servers seems to be blocked. This is very bizarre and strange. my iPhone, iPad, and simulators can load those pages just fine, but they will not load inside my app...
The code DOES work in playgrounds, just not in my app. I am not doing anything else with networking, and before this code is ran, the only thing that happens is some checks with local user settings to know if it should auto login, or request user and pass to be entered.
The error messages was along the lines of "could not open zepyrpanthur.com" or whatever site I used when it failed.
I'm hoping this is an issues with swift 2.0, and not a problem with my web servers, but who knows. maybe ssl is required for access now? tho some of the sites that did load weren't ssl, so I don't know, any ideas?