mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 13:20:57 +00:00
Swift 2.2
This commit is contained in:
1 parent
b14d5e281b
commit
3f231652fd
13 files changed
+36
-38
No files matched your search
@@ -63,7 +63,7 @@ public class APIManager: NSObject {
|
||||
|
||||
// set up reachability
|
||||
let operationQueue = manager!.operationQueue
|
||||
manager!.reachabilityManager.setReachabilityStatusChangeBlock({(AFNetworkReachabilityStatus status) -> Void in
|
||||
manager!.reachabilityManager.setReachabilityStatusChangeBlock({(status) -> Void in
|
||||
switch (status) {
|
||||
case AFNetworkReachabilityStatus.ReachableViaWWAN, AFNetworkReachabilityStatus.ReachableViaWiFi:
|
||||
operationQueue?.suspended = false
|
||||
@@ -106,7 +106,7 @@ public class APIManager: NSObject {
|
||||
}
|
||||
|
||||
public func teamImage(competitorId: String!, result: (imageUrl: String?) -> Void) {
|
||||
getTeam(competitorId, success: { (AFHTTPRequestOperation operation, AnyObject teamResponseObject) -> Void in
|
||||
getTeam(competitorId, success: { (operation, teamResponseObject) -> Void in
|
||||
|
||||
if let team = teamResponseObject as? [String: AnyObject],
|
||||
let imageUrl = team["imageUri"] as? String {
|
||||
@@ -115,7 +115,7 @@ public class APIManager: NSObject {
|
||||
result(imageUrl: nil)
|
||||
}
|
||||
|
||||
}, failure: { (AFHTTPRequestOperation operation, NSError error) -> Void in
|
||||
}, failure: { (operation, error) -> Void in
|
||||
// No image & that's ok
|
||||
result(imageUrl: nil)
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ class CourseViewController: UIViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:"newLocation:", name:LocationManager.NotificationType.newLocation, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(CourseViewController.newLocation(_:)), name:LocationManager.NotificationType.newLocation, object: nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
||||
@@ -26,10 +26,10 @@ public class DataManager: NSObject {
|
||||
print(managedObjectContext!)
|
||||
|
||||
// store new locations to database
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: "newLocation:", name: LocationManager.NotificationType.newLocation, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(DataManager.newLocation(_:)), name: LocationManager.NotificationType.newLocation, object: nil)
|
||||
|
||||
// save context when done tracking
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: "trackingStopped:", name: LocationManager.NotificationType.trackingStopped, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(DataManager.trackingStopped(_:)), name: LocationManager.NotificationType.trackingStopped, object: nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
||||
@@ -33,8 +33,8 @@ class GPSAccuracyView : UIView {
|
||||
barView.frame = bounds
|
||||
|
||||
// add listeners
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:"newLocation:", name:LocationManager.NotificationType.newLocation, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:"locationManagerFailed:", name:LocationManager.NotificationType.locationManagerFailed, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(GPSAccuracyView.newLocation(_:)), name:LocationManager.NotificationType.newLocation, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(GPSAccuracyView.locationManagerFailed(_:)), name:LocationManager.NotificationType.locationManagerFailed, object: nil)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,9 @@ class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDe
|
||||
}
|
||||
|
||||
// register for open custom URL events
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: "openUrl:", name: AppDelegate.NotificationType.openUrl, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(openUrl(_:)), name: AppDelegate.NotificationType.openUrl, object: nil)
|
||||
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: "checkEULA:", name: UIApplicationWillEnterForegroundNotification, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(checkEULA(_:)), name: UIApplicationWillEnterForegroundNotification, object: nil)
|
||||
|
||||
checkEULA(NSNotification.init(name: "", object: nil))
|
||||
|
||||
@@ -187,8 +187,6 @@ class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDe
|
||||
tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Automatic)
|
||||
case .Delete:
|
||||
tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: UITableViewRowAnimation.Automatic)
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class LeaderBoardViewController: UIViewController, UIWebViewDelegate, UIAlertVie
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
let serverUrl = DataManager.sharedManager.selectedCheckIn!.serverUrl
|
||||
let eventId = DataManager.sharedManager.selectedCheckIn!.eventId
|
||||
// let eventId = DataManager.sharedManager.selectedCheckIn!.eventId
|
||||
let leaderBoardName = DataManager.sharedManager.selectedCheckIn!.leaderBoardName.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
|
||||
let url = "\(serverUrl)/gwt/Leaderboard.html?name=\(leaderBoardName)&showRaceDetails=false&embedded=true&hideToolbar=true"
|
||||
webView!.loadRequest(NSURLRequest(URL: NSURL(string: url)!))
|
||||
|
||||
@@ -42,7 +42,7 @@ class LocationManager: NSObject, CLLocationManagerDelegate {
|
||||
if (CLLocationManager.authorizationStatus() == CLAuthorizationStatus.Denied) {
|
||||
return NSLocalizedString("Please enable location services for this app.", comment: "")
|
||||
}
|
||||
if (coreLocationManager.respondsToSelector("requestAlwaysAuthorization")) {
|
||||
if (coreLocationManager.respondsToSelector(#selector(CLLocationManager.requestAlwaysAuthorization))) {
|
||||
coreLocationManager.requestAlwaysAuthorization()
|
||||
}
|
||||
coreLocationManager.startUpdatingLocation()
|
||||
@@ -62,13 +62,13 @@ class LocationManager: NSObject, CLLocationManagerDelegate {
|
||||
NSNotificationQueue.defaultQueue().enqueueNotification(notification, postingStyle: NSPostingStyle.PostASAP)
|
||||
}
|
||||
|
||||
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [CLLocation]!) {
|
||||
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
||||
let location = locations.last
|
||||
let notification = NSNotification(name: NotificationType.newLocation, object: self, userInfo:LocationManager.dictionaryForLocation(location!))
|
||||
NSNotificationQueue.defaultQueue().enqueueNotification(notification, postingStyle: NSPostingStyle.PostASAP)
|
||||
}
|
||||
|
||||
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
|
||||
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
|
||||
let notification = NSNotification(name: NotificationType.locationManagerFailed, object: self, userInfo: ["error": error])
|
||||
NSNotificationQueue.defaultQueue().enqueueNotification(notification, postingStyle: NSPostingStyle.PostASAP)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import UIKit
|
||||
import AVFoundation
|
||||
|
||||
@objc protocol QRCodeManagerDelegate {
|
||||
optional var activityIndicatorView: UIActivityIndicatorView { get }
|
||||
optional var activityIndicatorView: UIActivityIndicatorView! { get }
|
||||
optional func qrCodeOK()
|
||||
optional func qrCodeCancel()
|
||||
}
|
||||
@@ -96,17 +96,17 @@ class QRCodeManager : NSObject, UIAlertViewDelegate {
|
||||
|
||||
// get event
|
||||
APIManager.sharedManager.getEvent(qrcodeData!.eventId,
|
||||
success: { (AFHTTPRequestOperation operation, AnyObject eventResponseObject) -> Void in
|
||||
success: { (operation, eventResponseObject) -> Void in
|
||||
self.eventDictionary = eventResponseObject as? [String: AnyObject]
|
||||
APIManager.sharedManager.getLeaderBoard(self.qrcodeData!.leaderBoardName,
|
||||
|
||||
// get leader board
|
||||
success: { (AFHTTPRequestOperation operation, AnyObject leaderBoardResponseObject) -> Void in
|
||||
success: { (operation, leaderBoardResponseObject) -> Void in
|
||||
self.leaderBoardDictionary = leaderBoardResponseObject as? [String: AnyObject]
|
||||
APIManager.sharedManager.getCompetitor(self.qrcodeData!.competitorId,
|
||||
|
||||
// get competitor
|
||||
success: { (AFHTTPRequestOperation operation, AnyObject competitorResponseObject) -> Void in
|
||||
success: { (operation, competitorResponseObject) -> Void in
|
||||
|
||||
APIManager.sharedManager.teamImage(self.qrcodeData!.competitorId, result: { (imageUrl) -> Void in
|
||||
|
||||
@@ -125,14 +125,14 @@ class QRCodeManager : NSObject, UIAlertViewDelegate {
|
||||
alertView.show()
|
||||
})
|
||||
|
||||
}, failure: { (AFHTTPRequestOperation operation, NSError error) -> Void in
|
||||
}, failure: { (operation, error) -> Void in
|
||||
self.delegate.activityIndicatorView?.stopAnimating()
|
||||
let title = String(format: NSLocalizedString("Couldn't get competitor %@", comment: ""), self.qrcodeData!.competitorId!)
|
||||
let alertView = UIAlertView(title: title, message: error.localizedDescription, delegate: self, cancelButtonTitle: NSLocalizedString("Cancel", comment: ""))
|
||||
alertView.tag = AlertView.ServerError.rawValue;
|
||||
alertView.show()
|
||||
|
||||
}) }, failure: { (AFHTTPRequestOperation operation, NSError error) -> Void in
|
||||
}) }, failure: { (operation, error) -> Void in
|
||||
self.delegate.activityIndicatorView?.stopAnimating()
|
||||
let title = String(format: NSLocalizedString("Couldn't get leader board %@", comment: ""), self.qrcodeData!.leaderBoardName!)
|
||||
let alertView = UIAlertView(title: title, message: error.localizedDescription, delegate: self, cancelButtonTitle: NSLocalizedString("Cancel", comment: ""))
|
||||
@@ -140,7 +140,7 @@ class QRCodeManager : NSObject, UIAlertViewDelegate {
|
||||
alertView.show()
|
||||
})
|
||||
|
||||
}, failure: { (AFHTTPRequestOperation operation, NSError error) -> Void in
|
||||
}, failure: { (operation, error) -> Void in
|
||||
self.delegate.activityIndicatorView?.stopAnimating()
|
||||
let title = String(format: NSLocalizedString("Couldn't get event %@", comment: ""), self.qrcodeData!.eventId!)
|
||||
let alertView = UIAlertView(title: title, message: error.localizedDescription, delegate: self, cancelButtonTitle: NSLocalizedString("Cancel", comment: ""))
|
||||
@@ -185,7 +185,7 @@ class QRCodeManager : NSObject, UIAlertViewDelegate {
|
||||
checkIn.imageUrl = teamImageURL
|
||||
|
||||
APIManager.sharedManager.checkIn(leaderBoardName, competitorId: competitorId, deviceUuid: DeviceUDIDManager.UDID, pushDeviceId: "", fromMillis: fromMillis,
|
||||
success: { (AFHTTPRequestOperation operation, AnyObject eventResponseObject) -> Void in
|
||||
success: { (operation, eventResponseObject) -> Void in
|
||||
|
||||
// create core data objects
|
||||
let event = DataManager.sharedManager.newEvent(checkIn)
|
||||
@@ -197,7 +197,7 @@ class QRCodeManager : NSObject, UIAlertViewDelegate {
|
||||
DataManager.sharedManager.saveContext()
|
||||
|
||||
self.delegate.qrCodeOK?()
|
||||
}, failure: { (AFHTTPRequestOperation operation, NSError error) -> Void in
|
||||
}, failure: { (operation, error) -> Void in
|
||||
self.delegate.activityIndicatorView?.stopAnimating()
|
||||
let title = String(format:NSLocalizedString("Couldn't check-in to %@", comment: ""), leaderBoardName);
|
||||
let alertView = UIAlertView(title: title, message: error.localizedDescription, delegate: self, cancelButtonTitle: NSLocalizedString("Cancel", comment: ""))
|
||||
|
||||
@@ -170,7 +170,7 @@ class RegattaViewController : UIViewController, UIActionSheetDelegate, UINavigat
|
||||
hoursLabel.text = String(format: "%.0f", arguments: [hours])
|
||||
minutesLabel.text = String(format: "%.0f", arguments: [minutes])
|
||||
loop?.invalidate()
|
||||
loop = NSTimer(timeInterval: 60, target: self, selector: "checkRegattaStatus", userInfo: nil, repeats: false)
|
||||
loop = NSTimer(timeInterval: 60, target: self, selector: #selector(RegattaViewController.checkRegattaStatus), userInfo: nil, repeats: false)
|
||||
NSRunLoop.currentRunLoop().addTimer(loop!, forMode:NSRunLoopCommonModes)
|
||||
}
|
||||
// during race
|
||||
@@ -265,14 +265,14 @@ class RegattaViewController : UIViewController, UIActionSheetDelegate, UINavigat
|
||||
DataManager.sharedManager.selectedCheckIn!.userImage = jpegData
|
||||
APIManager.sharedManager.postTeamImage(DataManager.sharedManager.selectedCheckIn!.competitorId,
|
||||
imageData: jpegData,
|
||||
success: { (AnyObject responseObject) -> Void in
|
||||
success: { (responseObject) -> Void in
|
||||
// http://wiki.sapsailing.com/wiki/tracking-app/api-v1#Competitor-Information-%28in-general%29
|
||||
// "Additional Notes: Competitor profile image left out for now."
|
||||
let responseDictionary = responseObject as![String: AnyObject]
|
||||
let imageUrl = (responseDictionary["teamImageUri"]) as! String;
|
||||
DataManager.sharedManager.selectedCheckIn!.imageUrl = imageUrl;
|
||||
},
|
||||
failure: { (NSError error) -> Void in
|
||||
failure: { (error) -> Void in
|
||||
let alertView = UIAlertView(title: NSLocalizedString("Failed to upload image", comment: ""), message: error.localizedDescription, delegate: self, cancelButtonTitle: NSLocalizedString("Cancel", comment: ""))
|
||||
alertView.tag = AlertView.UploadFailed.rawValue;
|
||||
alertView.show()
|
||||
@@ -302,9 +302,9 @@ class RegattaViewController : UIViewController, UIActionSheetDelegate, UINavigat
|
||||
competitorId: DataManager.sharedManager.selectedCheckIn!.competitorId,
|
||||
deviceUuid: DeviceUDIDManager.UDID,
|
||||
toMillis: toMillis,
|
||||
success: { (AFHTTPRequestOperation operation, AnyObject competitorResponseObject) -> Void in
|
||||
success: { (operation, competitorResponseObject) -> Void in
|
||||
},
|
||||
failure: { (AFHTTPRequestOperation operation, NSError error) -> Void in
|
||||
failure: { (operation, error) -> Void in
|
||||
}
|
||||
)
|
||||
DataManager.sharedManager.deleteCheckIn(DataManager.sharedManager.selectedCheckIn!)
|
||||
|
||||
@@ -43,7 +43,7 @@ class SendGPSFixController: NSObject {
|
||||
|
||||
/* See if any rows need to be uploaded. Schedule timer again. */
|
||||
func timer() {
|
||||
let loop = NSTimer.scheduledTimerWithTimeInterval(syncPeriod, target:self, selector:"timer", userInfo:nil, repeats:false)
|
||||
let loop = NSTimer.scheduledTimerWithTimeInterval(syncPeriod, target:self, selector:#selector(SendGPSFixController.timer), userInfo:nil, repeats:false)
|
||||
NSRunLoop.currentRunLoop().addTimer(loop, forMode:NSRunLoopCommonModes)
|
||||
|
||||
// get last 100 locations
|
||||
@@ -80,7 +80,7 @@ class SendGPSFixController: NSObject {
|
||||
APIManager.sharedManager.initManager(serverUrl)
|
||||
if APIManager.sharedManager.networkAvailable {
|
||||
APIManager.sharedManager.postGPSFixes(DeviceUDIDManager.UDID, gpsFixes: gpsFixes,
|
||||
success: { (AFHTTPRequestOperation operation, AnyObject competitorResponseObject) -> Void in
|
||||
success: { (operation, competitorResponseObject) -> Void in
|
||||
print("sent GPS fixes")
|
||||
for gpsFix in gpsFixes {
|
||||
DataManager.sharedManager.managedObjectContext!.deleteObject(gpsFix)
|
||||
@@ -88,7 +88,7 @@ class SendGPSFixController: NSObject {
|
||||
let notification = NSNotification(name: NotificationType.gpsFixesSynced, object: self)
|
||||
NSNotificationQueue.defaultQueue().enqueueNotification(notification, postingStyle: NSPostingStyle.PostASAP)
|
||||
},
|
||||
failure: { (AFHTTPRequestOperation operation, NSError error) -> Void in
|
||||
failure: { (operation, error) -> Void in
|
||||
print("error sending GPS fixes")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class SpeedViewController: UIViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:"newLocation:", name:LocationManager.NotificationType.newLocation, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(SpeedViewController.newLocation(_:)), name:LocationManager.NotificationType.newLocation, object: nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
||||
@@ -22,7 +22,7 @@ class TimerViewController: UIViewController, UIAlertViewDelegate {
|
||||
super.viewDidLoad()
|
||||
|
||||
// start tracking timer
|
||||
let timer = NSTimer(timeInterval: 0.1, target: self, selector: "timer:", userInfo: nil, repeats: true)
|
||||
let timer = NSTimer(timeInterval: 0.1, target: self, selector: #selector(TimerViewController.timer(_:)), userInfo: nil, repeats: true)
|
||||
NSRunLoop.currentRunLoop().addTimer(timer, forMode:NSRunLoopCommonModes)
|
||||
dateFormatter.dateFormat = "HH:mm:ss"
|
||||
dateFormatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)
|
||||
|
||||
@@ -35,9 +35,9 @@ class TrackingViewController : UIViewController {
|
||||
networkAvailabilityChanged()
|
||||
|
||||
// register for notifications
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:"networkAvailabilityChanged", name:APIManager.NotificationType.networkAvailabilityChanged, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:"newLocation:", name:LocationManager.NotificationType.newLocation, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:"locationManagerFailed:", name:LocationManager.NotificationType.locationManagerFailed, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(TrackingViewController.networkAvailabilityChanged), name:APIManager.NotificationType.networkAvailabilityChanged, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(TrackingViewController.newLocation(_:)), name:LocationManager.NotificationType.newLocation, object: nil)
|
||||
NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(TrackingViewController.locationManagerFailed(_:)), name:LocationManager.NotificationType.locationManagerFailed, object: nil)
|
||||
}
|
||||
|
||||
// MARK:- Notifications
|
||||
|
||||
Reference in new issue
Block a user