0

i've tried using

UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

but it doesn't return anything.
An alternative would be to send a message to the main app so it can set a notification, but this would mean that my app has to be listening for a change in Userdefaults or a change in my AppGroup Does anyone have any idea or advice? thanks

pguzman
  • 141
  • 1
  • 7

1 Answers1

0

I finally could set a notification from my extension, the problem was that i was trying to do it from a function that is called using a timer. (so now the problem is my timer is not working in the extension)
* this is what is not working *

_ = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(loopInExtension), userInfo: nil, repeats: true)

 @objc func loopInExtension() {
       UNUserNotificationCenter.current().add(request, nil)
}

So to set a notification i just had to add a notification, but not with a timer.

pguzman
  • 141
  • 1
  • 7
  • i succeed to set a timer and , i did this: var timer = Timer.init(timeInterval: 3, repeats: true, block: { (Timer) in // DO SOMEHING os_log("I CAN SEE THIS") }) RunLoop.main.add(timer, forMode: .defaultRunLoopMode) – pguzman Feb 09 '18 at 10:45
  • But if i set a notification inside my timer i just get 1 notification and after i dismiss it, i receive again another one just when i close my extension. i don't get what it's happening... i'll do some more digging – pguzman Feb 09 '18 at 10:47