添加 MFMessageComposeViewControllerTextMessageAvailabilityDidChange 通知

Add MFMessageComposeViewControllerTextMessageAvailabilityDidChange notification

我想将 MFMessageComposeViewControllerTextMessageAvailabilityDidChange 通知设置为观察者。我是 swift 的新手,所以我不清楚该怎么做。请帮助我。

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 {

 }
NotificationCenter.default.addObserver(self, selector: #selector(YourClass.yourFunction(notification:_)), name: Notification.Name.MFMessageComposeViewControllerTextMessageAvailabilityDidChange, object: nil)

函数:

func yourFunction(notification: Notification) { }

我还没有测试!但它应该工作。让我知道它是否有效

讨论

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.

来自官方文档