Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIApplication'

First it said that

'UIApplicationDidEnterBackground' has been renamed to 'UIApplication.didEnterBackgroundNotification'

and when I dot it,it said

Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIApplication'

func listenForBackgroundNotification() {
    observer = NotificationCenter.default.addObserver(forName: Notification.Name.UIApplicationDidEnterBackground, object: nil, queue: OperationQueue.main) { [weak self] _ in
        if let weakSelf = self {
            if weakSelf.presentedViewController != nil {
                weakSelf.dismiss(animated: true, completion: nil)
            }
            weakSelf.descriptionTextView.resignFirstResponder()

        }
    }
}
like image 329
mathias merlot Avatar asked Jul 22 '18 18:07

mathias merlot


4 Answers

Change

forName: Notification.Name.UIApplicationDidEnterBackground

to

forName: UIApplication.didEnterBackgroundNotification
like image 123
matt Avatar answered Nov 02 '22 03:11

matt


Error with Type 'NSNotification' has no member 'UIApplication' in swift4.2

NotificationCenter.default.addObserver(self, selector:#selector(handleNotification), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)

Need to Change accordingly

NotificationCenter.default.addObserver(self, selector:#selector(handleNotification), name: UIApplication.didEnterBackgroundNotification, object: nil)
like image 5
Deviyani Swami Avatar answered Nov 02 '22 05:11

Deviyani Swami


If UIApplicaiton.didEnterBackgroundNotificaiton isn't working, try just .UIApplicationDidEnterBackground instead.

like image 3
HeyImChris Avatar answered Nov 02 '22 04:11

HeyImChris


Xcode 11 , swift 5

UIApplication.didBecomeActiveNotification
like image 2
Ravikanth Avatar answered Nov 02 '22 03:11

Ravikanth