Skip to content

Commit

Permalink
Fixes issue CoolestProjects#57
Browse files Browse the repository at this point in the history
  • Loading branch information
oi2in authored Apr 22, 2017
1 parent 3c405e0 commit 1be2d4c
Showing 1 changed file with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
import Foundation
import UIKit
import CoreLocation
import UserNotifications

let SponsorBoxHeight: CGFloat = 300.0

class HomeViewController : BaseViewController {

class HomeViewController : BaseViewController, CLLocationManagerDelegate {

var locationManager : CLLocationManager = CLLocationManager()

let locMgr = CLLocationManager()

@IBOutlet weak var backgroundImage: UIImageView!
@IBOutlet weak var overlayView: UIView!
@IBOutlet weak var wrapperView: UIView!
Expand All @@ -23,12 +28,54 @@ class HomeViewController : BaseViewController {
let tableHeaderView = HomeTableHeaderView.headerView()!
let tableFooterView = HomeTableFooterView.footerView()!
let viewModel = HomeViewModel()
func setUpGeofenceForAirports() {

if #available(iOS 10.0, *) {
let center = CLLocationCoordinate2DMake(53.327890, -6.228936)
let region = CLCircularRegion(center: center, radius: 1000.0, identifier: "The RDS")
region.notifyOnEntry = true
region.notifyOnExit = false
self.locationManager.startMonitoring(for: region)

let trigger = UNLocationNotificationTrigger(region: region , repeats: false)
let Content = UNMutableNotificationContent()
Content.title = "Welcome To The RDS"
Content.body = "We Hope You Have A Great Day At CoolestProjects Today!!!"
Content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: "You're Near The RDS", content: Content, trigger: trigger)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()

UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Error: \(error)")
}
}

}
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if (status == CLAuthorizationStatus.authorizedAlways) {
self.setUpGeofenceForAirports()
}
}


override func viewDidLoad() {
super.viewDidLoad()
setupUI()

locMgr.desiredAccuracy = kCLLocationAccuracyBest

locMgr.requestAlwaysAuthorization()

locMgr.startUpdatingLocation()

locMgr.delegate = self
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
setupMask()
Expand Down Expand Up @@ -132,4 +179,3 @@ extension HomeViewController : UITableViewDataSource {
}

}

0 comments on commit 1be2d4c

Please sign in to comment.