androidapi-docs-iconCreated with Sketch.applearrowCreated with Sketch.codeCreated with Sketch.download-iconCreated with Sketch.faq-iconCreated with Sketch.flic-logogithubicon-closeCreated with Sketch.icon_affiliateCreated with Sketch.icon_b2b2cCreated with Sketch.icon_business_useCreated with Sketch.icon_joint_brandingCreated with Sketch.icon_kickbackCreated with Sketch.key-iconCreated with Sketch.next-iconCreated with Sketch.previous-iconCreated with Sketch.settingsCreated with Sketch.shortcutlabs-by-swedensmartphoneCreated with Sketch.

Flic for iOS: Part 1

Helpful Resources

Get the Flic app

The first thing we need to do is to make sure you have the Flic app installed.

Why do I need the Flic app?
The fliclib works with the Flic app so that you
don't have to worry about handling the Flics, scanning the Flics,
or monitoring the communication with them. All of that is taken care of
by the Flic app.

Download and install the Flic app. It's free and you can find it in the App Store.

Connect all your Flics to the app.

That's it! Now you will be able to use the Flic Grabber and get access
to the Flics inside your own app. Don't worry, we'll go through
how this is done soon.

Set up Xcode

The next thing that we need to do is configure Xcode to properly use fliclib.

Import the fliclib.framework file to your project.

Under Project Settings -> Build Settings, set the flag
Allow Non-modular includes in Framework Modules to
Yes.

Under Settings -> General, remove fliclib.framework
from Linked frameworks and Binaries since it will
be automatically added in the next step.

Now, on the same view, press the + sign under
Embedded Binaries and add fliclib.framework
from the list. This should add fliclib.framework to
Linked frameworks and Binaries as well.

In your project plist file, you need to register your app to handle
URL scheme calls. This is needed when you fetch a Flic object from
the Flic App. You also need to add the Flic app to the list of
Application Query Schemes. Don't worry, we will explain this
in greater detail later on. Make sure that your plist file contains
something like this:
Of course, make sure that you select a URL that is unique
to your specific app. That's it! Xcode is now properly set
up to integrate Flic and we can start coding.

Integrate Flic

We will now go through the steps needed in order to fully integrate
Flic in your code. We will do it in a blank Xcode project.

Import fliclib/fliclib.h where applicable.
In this basic example we will just add it to the view controller
header file. We also went ahead and added the Button and
Manager protocols.

In the implementation file, we need to configure the manager singleton that
will handle all Flic buttons. In this case we did so in the
viewDidLoad method. The appID
and appSecret parameters are unique for every application
and can be generated on our developer portal. The backgroundExecution
flag specifies whether or not you plan to use Flic for background execution. For this
very simple example, we will set it to NO. The defaultButtonDelegate
can be set if you know in advance where you want all the button delegate callbacks. The
manager singleton has to be configured once on every application launch and it will not be
usable unless this is done.

We now have a manager that we can use to grab a button from the
Flic app, but before we do that we need to properly set up our
URL scheme so that the callback works properly. To accomplish this we
have to add a method application:openURL:sourceApplication:annotation:
to our AppDelegate.m that will receive the URL callback. In this callback
we can just forward it to the manager singleton.

We are now all set to grab our first Flic button.
To do this we need to call the grabFlicFromFlicAppWithCallbackUrlScheme:
method on the manager singleton. What this call will do is open
up the Flic app and present the user with a view where they can
choose one of their connected Flics. Once the user has chosen one
Flic, it will redirect back to the specified callback URL. We
decided to put this feature in an IBAction and
hook that up to a UIButton to be displayed in the UI.

We now need to implement the flicManager:didGrabFlicButton:withError:
callback in order to get notified when a button has been grabbed.
If no error occurred, a new SCLFlicButton instance that is tied to the
selected physical Flic has been created. The first thing that we should remember to do
is to set the delegate here, unless you have not already set the default delegate on
the manager (which we have already done in this example). This would also be a good place
do all of your custom button settings in case you need any behavior that is different from
the default.

That's it! You now have a Flic button tied to your app, and
you can start using it however you like. For example, lets implement
the flicButton:didReceiveButtonDown:age: delegate method
to make sure that things are working as they should.
Remember that it might take a second or two to connect
to the Flic. If you want to be notified of when the Flic is
properly connected and ready to use, you can also implement the
flicButtonIsReady: method.

If you are interested in background capabilities then please
continue and read part 2 of this tutorial.