user2640633
user2640633

Reputation:

swift 2 local alert for multiple dates in array

I have an array of nsdates and I want to create a notification for each of them to happen when the time matches the current times.

so far i have this

for item in stuffThree {

            print("test")

            var notification:UILocalNotification = UILocalNotification()
            notification.category = "test1"
            notification.alertBody = "test2"
            notification.fireDate  = item
            print(item)

            UIApplication.sharedApplication().scheduleLocalNotification(notification)

        }

As of now I am not getting anything. What i do is create a date a minute ahead and then let the clock tick down and wait and nothing happens.

Any ideas?

Upvotes: 0

Views: 115

Answers (2)

D. Greg
D. Greg

Reputation: 1000

Try this.

notification.fireDate = NSDate(timeIntervalSinceNow: 5)

You should read This on HackingWithSwift. It should help you out.

Upvotes: 0

sschale
sschale

Reputation: 5188

A couple suggestions:

  1. Set notification.alertBody = "Test"
  2. Call localNotification.timeZone = NSTimeZone.defaultTimeZone()
  3. Check your outputs with print(notification.fireDate) and print(notification)
  4. If in the simulator, you may not have the notification pop up if the app is open, so close it (shift+cmd+h)

Upvotes: 1

Related Questions