'orientationDidChangeNotification has been renamed to 'NSNotification.Name.UIDeviceOrientationDidChange'

i am updated to flutter 2.10 and get this issue in ios MLKit in the class

OrientationHandler

in this section of the handler code

    NotificationCenter.default.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: nil, using: orientationDidChange(_:))
 

i get this error :

'orientationDidChangeNotification' has been renamed to 'NSNotification.Name.UIDeviceOrientationDidChange'

this class written like

class OrientationHandler {

var lastKnownOrientation: UIDeviceOrientation!

init() {
    setLastOrientation(UIDevice.current.orientation, defaultOrientation: .portrait)
    UIDevice.current.beginGeneratingDeviceOrientationNotifications()
    
    
    
    NotificationCenter.default.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: nil, using: orientationDidChange(_:))
 
    
    
    
}

func setLastOrientation(_ deviceOrientation: UIDeviceOrientation, defaultOrientation: UIDeviceOrientation?) {
    
    // set last device orientation but only if it is recognized
    switch deviceOrientation {
    case .unknown, .faceUp, .faceDown:
        lastKnownOrientation = defaultOrientation ?? lastKnownOrientation
        break
    default:
        lastKnownOrientation = deviceOrientation
    }
}

func orientationDidChange(_ notification: Notification) {
    let deviceOrientation = UIDevice.current.orientation
    
    setLastOrientation(deviceOrientation, defaultOrientation: nil)
}

deinit {
    UIDevice.current.endGeneratingDeviceOrientationNotifications()
  }
}

how to solve this error



Solution 1:[1]

after searching , i solve it like this

    NotificationCenter.default.addObserver(forName: NSNotification.Name.UIDeviceOrientationDidChange, object: nil, queue: nil, using: orientationDidChange(_:))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ????? ???? ????? ???????