For the purpose of the tutorial, we will assume you already have an existing iOS application in which you have a feed or list of items. As the Flipper team, we obviously concern ourselves mostly with sea mammals, so this is what our app displays. The actual display logic is not what's interesting here, but how we can make this data available in our Flipper desktop app.
You can find the source code of the project on GitHub.
Creating a Plugin
On iOS, a Flipper plugin is a class that implements the
The interface is rather small and only comprises four methods:
package.jsonwe will look into later in this tutorial.
(void)didConnect:(id<FlipperConnection>)connection: This method is called when the desktop client connects and is ready to receive or send data.
(void)didDisconnect: We're sure you can figure this one out.
(BOOL)runInBackground: Unless this is true, only the currently selected plugin in the Flipper UI can communicate with the device. Its an optional method which you can override. Default value used is
Let's implement these methods for our sealife app:
The two interesting bits here are
connection.send sends a message
to the desktop app and is identified with the name "newRow".
For our sample app, we're dealing with a static data source. However, in real
life, you will likely dynamically receive new data as the user interacts with
the app. So while we just send all the data we have at once in
you would normally set up a listener here to instead call
connection.send("newRow", params) as new data
params are nothing but a dictionary which contains the data which you want to send over the wire to the desktop app.
Registering your Plugin
Now all you need to do is let Flipper know about your new plugin. You do this
add on your
FlipperClient, which is normally created
at application startup.