【发布时间】:2015-07-07 10:47:45
【问题描述】:
我正在处理外部附件框架,这是我注册通知的代码..
override func viewDidLoad() {
super.viewDidLoad()
EAAccessoryManager.sharedAccessoryManager().registerForLocalNotifications()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "accessoryDidConnectNotify", name: EAAccessoryDidConnectNotification, object: nil)
}
这是我的方法处理函数...
func accessoryDidConnectNotify(notification: NSNotification){
let alert : UIAlertController = UIAlertController(title: "Alert", message: "MFi Accessory Connected", preferredStyle:UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "ok", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
}))
self.presentViewController(alert, animated: true, completion: nil)
我的问题是,如果我没有在accessoryDidConnectNotify 函数中提供任何参数,那么当我插入MFi 附件时,应用程序会在警报视图中正常工作..
(i.e) func accessoryDidConnectNotify(){ // works fine (with no arguments)
}
但我需要在我的 accessoryDidConnectNotify 函数中使用 NSNotification 对象来获取附件的名称 ...但是如果我添加 NSNotification 对象,则应用程序会在插入 MFi 附件时崩溃...
(i.e) func accessoryDidConnectNotify(notification: NSNotification){
} // crashes app (with arguments)
如果有人也遇到过这个问题...请分享
【问题讨论】:
-
把
accessoryDidConnectNotify改成accessoryDidConnectNotify: -
您的函数确实有一个参数,因此选择器名称必须是@DharmeshKheni 所写的
accessoryDidConnectNotify:。这是more info。
标签: ios swift ios8 nsnotificationcenter nsnotifications