Class: Takeoff::Reminders
- Inherits:
-
Object
- Object
- Takeoff::Reminders
- Defined in:
- lib/project/reminders.rb
Class Method Summary collapse
- .all ⇒ Object
- .count ⇒ Object
- .notifications ⇒ Object
- .reset ⇒ Object
- .schedule(opts) ⇒ Object
- .setup ⇒ Object
Class Method Details
.all ⇒ Object
72 73 74 |
# File 'lib/project/reminders.rb', line 72 def all UIApplication.sharedApplication.scheduledLocalNotifications end |
.count ⇒ Object
76 77 78 |
# File 'lib/project/reminders.rb', line 76 def count all.count end |
.notifications ⇒ Object
80 81 82 |
# File 'lib/project/reminders.rb', line 80 def notifications all end |
.reset ⇒ Object
65 66 67 68 69 70 |
# File 'lib/project/reminders.rb', line 65 def reset UIApplication.sharedApplication.tap do |app| app.applicationIconBadgeNumber = 0 app.cancelAllLocalNotifications end end |
.schedule(opts) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/project/reminders.rb', line 16 def schedule (opts) raise "You must specify a :body" unless opts[:body] raise "You must specify a :fire_date" unless opts[:fire_date] opts = { action: nil, launch_image: nil, badge_number: 0, has_action: true, repeat: { calendar: nil, interval: 0 }, time_zone: NSTimeZone.defaultTimeZone, sound: UILocalNotificationDefaultSoundName, user_info: {} }.merge(opts) # Fix the repeat if they just send the interval. unless opts[:repeat].is_a? Hash opts[:repeat] = { calendar: NSCalendar.currentCalendar, interval: opts[:repeat] } end # Interpret the fire date to an NSDate class it they specified a number of seconds if opts[:fire_date].is_a? Fixnum opts[:fire_date] = NSDate.dateWithTimeIntervalSinceNow(opts[:fire_date]) end notification = UILocalNotification.new.tap do |notif| notif.alertAction = opts[:action] notif.alertBody = opts[:body] notif.alertLaunchImage = opts[:launch_image] notif.applicationIconBadgeNumber = opts[:badge_number] notif.timeZone = opts[:time_zone] notif.fireDate = opts[:fire_date] notif.hasAction = opts[:has_action] notif.repeatCalendar = opts[:repeat][:calendar] notif.repeatInterval = opts[:repeat][:interval] notif.soundName = opts[:sound] notif.userInfo = opts[:user_info] end UIApplication.sharedApplication.scheduleLocalNotification notification notification end |
.setup ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/project/reminders.rb', line 5 def setup version_components = Device.ios_version.split '.' if version_components[0].to_i >= 8 types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert notificationSettings = UIUserNotificationSettings.settingsForTypes(types, categories:nil) UIApplication.sharedApplication.registerUserNotificationSettings(notificationSettings) else UIApplication.sharedApplication.registerForRemoteNotificationTypes((UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)) end end |