Instantly share code, notes, and snippets.

Embed
What would you like to do?
MFi Devices list
import UIKit
import ExternalAccessory
class DevicesViewController: UITableViewController {
var manager = EAAccessoryManager.sharedAccessoryManager()
override func viewDidLoad() {
super.viewDidLoad()
manager.registerForLocalNotifications()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("deviceConnected:"), name: EAAccessoryDidConnectNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("deviceDisconnected:"), name: EAAccessoryDidDisconnectNotification, object: nil)
}
func deviceConnected(notification: NSNotification) {
tableView.reloadData()
if let acc = notification.userInfo![EAAccessoryKey] {
showAccessoryInfo(acc as! EAAccessory)
}
}
func deviceDisconnected(notification: NSNotification) {
tableView.reloadData()
}
func showAccessoryInfo(accessory: EAAccessory) {
UIAlertView(title: "\(accessory.manufacturer) \(accessory.name)", message: "\(accessory.description)", delegate: nil, cancelButtonTitle: "OK").show()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return manager.connectedAccessories.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let acc = manager.connectedAccessories[indexPath.row]
cell.textLabel?.text = "\(acc.manufacturer) \(acc.name)"
cell.detailTextLabel?.text = "\(acc.modelNumber) \(acc.serialNumber)\n fr:\(acc.firmwareRevision) hr: \(acc.hardwareRevision)"
return cell
}
override func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
let acc = manager.connectedAccessories[indexPath.row]
showAccessoryInfo(acc)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>com.verifone.pmr.zontalk</string>
<string>com.verifone.pmr.xpi</string>
</array>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment