androidapi-docs-iconCreated with Sketch.applearrowCreated with Sketch.codeCreated with with Sketch.faq-iconCreated with Sketch.githubicon-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 with Sketch.previous-iconCreated with Sketch.settingsCreated with Sketch.shortcutlabs-by-swedensmartphoneCreated with Sketch.


Flic for iOS: Part 1

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.

  1. Download and install the Flic app. It's free and you can find it in the App Store.
  2. Connect all your Flics to the app.
  3. 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.

  1. Import the fliclib.framework file to your project.
  2. Under Project Settings -> Build Settings, set the flag Allow Non-modular includes in Framework Modules to Yes. Show how to allow non-modular includes in Xcode
  3. Under Settings -> General, remove fliclib.framework from Linked frameworks and Binaries since it will be automatically added in the next step.
  4. 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. Show how to embed the fliclib framework in Xcode
  5. 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: Show how to register an app to handle URL scheme calls. 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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

Continue to part 2