Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Stephen McMillan
iOS Development with Swift Techdegree Graduate 33,994 PointsNSNotificationCenter calls selector multiple times - SWIFT
Im using NSNotificationCenter to post a notification if the applicationDidBecomeActive method detect that the application is badged (Local Notification)
NSNotificationCenter.defaultCenter().postNotificationName("testNotification", object: nil)
Prior to this - In the viewWillAppear of my ViewController im adding the observer.
NSNotificationCenter.defaultCenter().addObserver(self, selector: "testSelector", name: "testNotification", object: nil)
When the notification is posted and the selector is called it gets called twice - In theory it should only be called once?
I've made sure that the observer is only added once and tried removing it before adding again. But it does the same thing.
Any help would be great! :)
2 Answers
Jason Woolard
11,563 PointsTry moving this to your viewDidLoad instead of viewWillAppear.
Stephen McMillan
iOS Development with Swift Techdegree Graduate 33,994 PointsTried that :/ No luck. Jason Woolard
Is there any additional ways to detect a local notifications from the app delegate?