Created
October 8, 2015 19:52
-
-
Save codebeaulieu/6858b9ec9446a3c5c792 to your computer and use it in GitHub Desktop.
Notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static func evaluateMemberStatusNotifications() { | |
let userDefaults = Global.app.userDefaults | |
let localNotification: UILocalNotification = UILocalNotification() | |
print("evaluating profile notifications") | |
// is the user active? if so no notification | |
let isActive : Bool = userDefaults.valueForKey("ActiveMember") as! Bool // false == inactive | |
print("is the user active?") | |
if !isActive { | |
print("user is not active, checking if notification code has run") | |
// if userDefaults is nil for this value, we'll set it to false | |
if (userDefaults.valueForKey("ProfileNotificationHasRun") == nil) { | |
print("nil! setting ProfileNotificationHasRun to 'false'") | |
userDefaults.setValue(false, forKey: "ProfileNotificationHasRun") | |
} | |
let statusNotification = userDefaults.valueForKey("ProfileNotificationHasRun") as! Bool | |
// has this code been run? If not run it | |
if !statusNotification { | |
print("running notification code") | |
// we schedule a notification | |
localNotification.alertAction = "Inactive Membership" | |
localNotification.alertBody = "Our system has detected that your membership is inactive. You may continue using this application though some features may not be available to you until your membership is reinstated." | |
localNotification.fireDate = NSDate(timeIntervalSinceNow: 5) | |
localNotification.category = "status" | |
localNotification.repeatInterval = .Day | |
UIApplication.sharedApplication().scheduleLocalNotification(localNotification) | |
userDefaults.setValue(true, forKey: "ProfileNotificationHasRun") | |
} else { | |
print("notification code has already run, time interval has been set") | |
} | |
} else { | |
print("member is active, remove Inactive notification") | |
// if the member is active, we remove the notification so the user doesn't | |
// keep getting notified | |
UIApplication.sharedApplication().cancelLocalNotification(localNotification) | |
userDefaults.setValue(false, forKey: "ProfileNotificationHasRun") | |
} | |
// when is the users due date? & have the dues notifications already be set? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment