-1

I want to write an app that uses local notification and send me notification regardless of which view/screen I am on a multi view application.

For simplicity, let say I have 2 view controllers each has a button on it.

For example

class ViewController1: UIViewController {

has a button on it and when is pressed will take me to

class ViewController2: UIViewController {

and this class has button on it and when is pressed will take me back to ViewController1

so far I have no issues with implementing this, but I want to have a class that handles the local notification in a way to send me “Hello Word” alert every mins regardless of if I am currently on ViewController1 or ViewController2 screen.

I don’t want the code that handles the local notification be part of either ViewController1 or ViewController2, but rather have its own class.

So basically all I want a class that handles local notification and not be part of any viewcontroller. What is the requirements for writing such a class in Swift? is there an example that someone can share?

Thanks

Borna

borna
  • 906
  • 3
  • 12
  • 32

1 Answers1

0

This is actually a fairly non-trivial thing to do. If you're capable of reading obj-c and converting it to swift, this answer does exactly what you want:

How to present UIAlertController when not in a view controller?

If you aren't, more or less you create a new UIWindow, and present your UIAlerController there. This is probably the cleanest way to do this while being totally agnostic of whatever screen you're on in the other window.

And as for what triggers this to show, just use a NSTimer. Hope that helps!

Community
  • 1
  • 1
tbondwilkinson
  • 1,067
  • 2
  • 8
  • 16