Verified Commit e58ac6a1 authored by Eyad Hasan's avatar Eyad Hasan

Created a new struct to store the global var for the network. Network var...

Created a new struct to store the global var for the network.  Network var gets flipped to true in the download code instead of using a new file.  This variable is going to be used primarily for smaller functions like alerts n such
parent 87043aee
......@@ -31,6 +31,7 @@ class DownloadController: NSObject {
let httpResponse = response as! HTTPURLResponse
let statusCode = httpResponse.statusCode
if (statusCode == 200) {
networkCheck.network = true
if let dataN = data {
if let json = try? JSONSerialization.jsonObject(with: dataN, options: []) as? [[String: Any]] {
// Map function to iterate through each JSON tree
......
......@@ -20,7 +20,10 @@ enum Day: Int {
// Add functions here later if we need them
}
struct networkCheck {
static var network:Bool = false
}
class Facility: Object, MapContext, Mappable {
@objc dynamic var slug = ""
......
......@@ -14,16 +14,17 @@ public class Reachability {
var status:Bool = false
let url = NSURL(string: "https://api.srct.gmu.edu/whatsopen/v2/facilities/?format=json")
let request = NSMutableURLRequest(url: url! as URL)
let url = URL(string: "https://api.srct.gmu.edu/whatsopen/v2/facilities/?format=json")
var request = URLRequest(url: url! as URL)
request.httpMethod = "HEAD"
request.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData
request.cachePolicy = URLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData
request.timeoutInterval = 10.0
var response:URLResponse?
do {
let _ = try NSURLConnection.sendSynchronousRequest(request as URLRequest, returning: &response) as NSData?
//let _ = try NSURLConnection.sendSynchronousRequest(request as URLRequest, returning: &response) as NSData?
let _ = try URLSession.dataTaskWithRequest(request as URLRequest, completionHandler: &response)
}
catch let error as NSError {
print(error.localizedDescription)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment