I deal with the external infrastructure of accessories, and here is my code for registering inaccuracy.
override func viewDidLoad() { super.viewDidLoad() EAAccessoryManager.sharedAccessoryManager().registerForLocalNotifications() NSNotificationCenter.defaultCenter().addObserver(self, selector: "accessoryDidConnectNotify", name: EAAccessoryDidConnectNotification, object: nil) }
And here is my method processing function ...
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)
And my problem is that if I do not give any parameters inside the accessoriesDidConnectNotify function, the application works fine with a warning view when I insert an MFi accessory.
(ie) func accessoryDidConnectNotify(){
but I need an NSNotification object that will be used inside my accessoriesDidConnectNotify function to get the name of the accessory ... but if I add an NSNotification object, the application crashes when I insert the MFi accessory ...
(ie) func accessoryDidConnectNotify(notification: NSNotification){ }
If someone also encountered a problem ... please share
source share