Reputation: 259
I want to set MFMessageComposeViewControllerTextMessageAvailabilityDidChange notification to observer. I am new to swift so, i am not clear about how to do that. Please help me.
Upvotes: -1
Views: 165
Reputation: 2684
NotificationCenter.default.addObserver(self, selector: #selector(YourClass.yourFunction(notification:_)), name: Notification.Name.MFMessageComposeViewControllerTextMessageAvailabilityDidChange, object: nil)
Function:
func yourFunction(notification: Notification) { }
I have not tested yet! But it's should work. Let me know if it's works
Discussion
Upon receiving this notification, query its userInfo dictionary with the MFMessageComposeViewControllerTextMessageAvailabilityKey key. If the availability of text message sending has changed, your app should invalidate caches and update its user interface as appropriate.
From official documentation
Upvotes: 1
Reputation: 1447
Swift 3.0
let notificationCenter = NotificationCenter.default // Note that default is now a property, not a method call
notificationCenter.addObserver(forName: Notification.Name(rawValue: MFMessageComposeViewControllerTextMessageAvailabilityDidChange),object: nil, queue: nil,using: catchNotification)
//handle the notification fired method
func catchNotification(notification: Notification) -> Void {
}
Upvotes: 0