0

I'm generating random text with as a local notification, my problem is that notification repeat the same text everyday and wont pick another text from that random text, and that problem is only active on local notifications, it's work well on labels and this is my code.

  let myNotification:UILocalNotification = UILocalNotification()
        myNotification.category = "text"
        myNotification.alertBody = text.randomText()
        myNotification.soundName = "sound.wav"
        myNotification.fireDate = date
        myNotification.repeatInterval = NSCalendarUnit.Day
  UIApplication.sharedApplication().scheduleLocalNotification(myNotification)

UPDATE : I use Array of Strings named(textArray) with the following function to generate the random text.

    func randomText() -> String {
        let unsignedArrayCount = UInt32(textArray.count)
        let unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
        let randomNumber = Int(unsignedRandomNumber)
        return textArray[randomNumber]
    }
Omar
  • 185
  • 2
  • 14
  • 1
    There is no way to answer this with the code you provided. Can you show the text.randomText() function definition? – Sethmr Jun 24 '16 at 21:44
  • Are you storing those sentences inside an array? – Tarvo Mäesepp Jun 24 '16 at 21:44
  • Yes I'm using array of strings with random function, I updated my Question. – Omar Jun 24 '16 at 22:01
  • @Omar, I just used your code and it worked well in playground. I think you have nil somewhere. And BTW I think you are not generating random text but you are picking random sentence or word from an array. Am I right? – Tarvo Mäesepp Jun 24 '16 at 22:05
  • Dear @Tarvo I know my code working well, let me explain what issue I have. Let's say the app schedule notification with text ("demoText"), and the second time it have to schedule another text ("demoText2") or ("demoText3") or("demoText4"). the notification still shows the first scheduled notification ("demoText"). Not the other ones and repeat it in every schedule time – Omar Jun 24 '16 at 22:13
  • @Tarvo .Just like you said my code is picking a random text, is there another way to pick random text, what do you think if I use a index of text? – Omar Jun 24 '16 at 23:19
  • How are you seeding the random number generator? – Feldur Jun 25 '16 at 07:16

0 Answers0