Reviewed By: passy Differential Revision: D17863710 fbshipit-source-id: 5b249bdd1c06d3a526b250b035b797d0c8e796eb
48 lines
1.4 KiB
Swift
48 lines
1.4 KiB
Swift
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import UIKit
|
|
import FlipperKit
|
|
|
|
class CommunicationDemoViewController: UIViewController, UITableViewDataSource, FlipperKitExampleCommunicationResponderDelegate {
|
|
@IBOutlet weak var messageField: UITextField!
|
|
@IBOutlet weak var tableView: UITableView!
|
|
var messageArray: [String] = []
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
FlipperKitExamplePlugin.sharedInstance()?.delegate = self
|
|
}
|
|
|
|
@IBAction func tappedTriggerNotification(_ sender: UIButton) {
|
|
FlipperKitExamplePlugin.sharedInstance()?.triggerNotification();
|
|
}
|
|
|
|
@IBAction func tappedSendMessage(_ sender: UIButton) {
|
|
if let message = self.messageField.text {
|
|
FlipperKitExamplePlugin.sharedInstance()?.sendMessage(message);
|
|
}
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "reusableCell", for: indexPath)
|
|
cell.textLabel?.text = messageArray[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return messageArray.count;
|
|
}
|
|
|
|
func messageReceived(_ msg: String!) {
|
|
messageArray.append(msg)
|
|
DispatchQueue.main.async { [weak self] in
|
|
self?.tableView.reloadData();
|
|
}
|
|
}
|
|
}
|