-2

In Appdelegate.swift,

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {

 NSNotificationCenter.defaultCenter().postNotificationName("notification", object: nil, **userInfo: notification.userInfo**)
}

In ViewController.swift

I included observer and method

override func viewDidLoad() {
    super.viewDidLoad()

    NSNotificationCenter.defaultCenter().addObserver(self, selector:"handleNotification", name: "notification", object: nil)
 }

func handleNotification(notification: NSNotification){
    print("enter ")
}

When i handle notification, it crashes "unrecognised selector sent to instance" what is problem?

Sunil Prajapati
  • 473
  • 5
  • 17

2 Answers2

0

For Swift 3

Change your notification observer to

NotificationCenter.default.addObserver(self, selector: #selector(handleNotification(with:)), name: notification, object: nil)

Try to change your handleNotification function to:

func handleNotification(with notification: Notification){
    print("enter ");
}
0

Please add this and check it.

NSNotificationCenter.defaultCenter().addObserver(self, selector:#selector(handleNotification(_:)), name: "notification", object: nil)
Sunil Prajapati
  • 473
  • 5
  • 17