1

I have a class with a function that monitors location and activity. When said class detects the user has parked I want it to send a notification to said user in order for him/her to take action.

Here's the function:

func park() -> CLLocation {
    var location = Location()
    while CMMotionActivity().automotive == true {
        //Track Location
    }
    location.storeParkLoc()
    //Send Notification
    return location.parkLoc
}

And here's the notification:

func setUp() {

    let notificationSettings: UIUserNotificationSettings! = UIApplication.sharedApplication().currentUserNotificationSettings()

    if notificationSettings.types == UIUserNotificationType.None {

        var notificationTypes: UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Sound

        var didPark = UIMutableUserNotificationAction()
        didPark.identifier = "didPark"
        didPark.title = "Yes"
        didPark.activationMode = UIUserNotificationActivationMode.Background
        didPark.destructive = false
        didPark.authenticationRequired = false

        var didNotPark = UIMutableUserNotificationAction()
        didNotPark.identifier = "didNotPark"
        didNotPark.title = "No"
        didNotPark.activationMode = UIUserNotificationActivationMode.Background
        didNotPark.destructive = true
        didNotPark.authenticationRequired = false

        let actionsArray = NSArray(objects: didPark, didNotPark)

        var didParkOptions = UIMutableUserNotificationCategory()
        didParkOptions.identifier = "didParkOptions"
        didParkOptions.setActions(actionsArray as [AnyObject], forContext: UIUserNotificationActionContext.Minimal)

        let categoriesForSettings = NSSet(objects: didParkOptions)

        let newNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: categoriesForSettings as Set<NSObject>)
        UIApplication.sharedApplication().registerUserNotificationSettings(newNotificationSettings)

    }
}

How do I get it to fire in the other function?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.