SCLFlicManager

@interface SCLFlicManager : NSObject

This singleton class is required in order to perform any bluetooth LE communication with the Flic/PbF . You need to use this in order to scan for, and discover, new buttons. The object will keep track of all the buttons that are associated to the specific iOS device. It is important to mention that the SCLFlicManager does not support the regular state preservation and restoration protocol for view controllers, meaning that it does not support NSCoding. Instead, all of the state preservation will be taken cared of for you by the manager. Simply call the class configuration method on every app boot and averything will be restored as it should. Once the manager has been restored you can collect the associated Flic/PbF objects using the knownButtons: method.

  • The delegate object that will receive all the Flic/PbF related events. See the definition of the SCLFlicManagerDelegate to see what callbacks are available.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<SCLFlicManagerDelegate> delegate;

    Swift

    weak var delegate: SCLFlicManagerDelegate? { get set }
  • The default delegate that will be assigned to all buttons both when they are grabbed, scanned, or during state restoration. This is not required since the button delegates can be set manually. If you decide to set them manually then you have to also remember to set them on every application restoration when the manager sends the flicManagerDidRestoreState callback. See the definition of the SCLFlicButtonDelegate to see what callbacks are available.

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) id<SCLFlicButtonDelegate> defaultButtonDelegate;

    Swift

    weak var defaultButtonDelegate: SCLFlicButtonDelegate? { get set }
  • The current bluetoothState of the manager. A bluetoothDidChangeState event will be generated on the SCLFlicManagerDelegate whenever this state has changed. When the manager is initialized the state will be SCLFlicManagerBluetoothStateUnknown by default. You will not be able to do any bluetooth related tasks until the manager properly changes to SCLFlicManagerBluetoothStateOn.

    Declaration

    Objective-C

    @property (nonatomic, readonly) SCLFlicManagerBluetoothState bluetoothState;

    Swift

    var bluetoothState: SCLFlicManagerBluetoothState { get }
  • This is a flag that lets you know if the manager is enabled for Bluetooth LE communication. This can be toggled on/off using the enable and disable. When this property is set to NO, then no Bluetooth LE communication will be allowed. This means that no communication with a Flic/PbF can be made.

    Declaration

    Objective-C

    @property (readonly, getter=isEnabled) BOOL enabled;

    Swift

    var isEnabled: Bool { get }
  • Use this to access the manager singleton. This will only work if a call to configureWithDelegate:appID:appSecret:backgroundExecution: has been made once this app session, otherwise nil will be returned.

    Declaration

    Objective-C

    + (instancetype _Nullable)sharedManager;

    Swift

    class func shared() -> Self?
  • The initialization call to use when you want to configure the manager. This will initiate a SCLFlicManager and do the proper preparation needed in order to start the bluetooth communication with flic buttons. Using more than one manager in the same application is not supported, which is why we decided to go with the singleton approach.

    When choosing the restore option all settings on the manager will be restored. This will also recreate all SCLFlicButtons that had previously been used with this manager unless they had been manually removed using the forgetButton: method. All the flic objects that had a pending connection before will be set to the same state after restoration. When the restoration process is complete the manager will call the flicManagerDidRestoreState: method of its delegate object. At that point, unless you have already set the defaultButtonDelegate, it is recommended that you call knownButtons: in order to collect all the button objects and re-set their delegate.

    Declaration

    Objective-C

    + (instancetype _Nullable)
        configureWithDelegate:(id<SCLFlicManagerDelegate> _Nullable)delegate
        defaultButtonDelegate:(id<SCLFlicButtonDelegate> _Nullable)buttonDelegate
                        appID:(NSString *_Nonnull)appID
                    appSecret:(NSString *_Nonnull)appSecret
          backgroundExecution:(BOOL)background;

    Swift

    class func configure(with delegate: SCLFlicManagerDelegate?, defaultButtonDelegate buttonDelegate: SCLFlicButtonDelegate?, appID: String, appSecret: String, backgroundExecution background: Bool) -> Self?

    Parameters

    delegate

    The delegate that all callbacks will be sent to.

    buttonDelegate

    This delegate will automatically be set to new buttons and old buttons on app restoration.

    appID

    This is the App-ID string that the developer is required to have in order to use the fliclib framework.

    appSecret

    This is the App-Secret string that the developer is required to have in order to use the fliclib framework.

    background

    Flag that specifies if want to configure the Flic manager to support background execution. If YES, then you also have to check the “Uses Bluetooth LE accessories” option under your projects Background Modes settings.

  • Starts a scan for buttons. Each time a new button is found the manager will call the didDiscoverButton:withRSSI: delegate method. Starting a scan will have no effect if the device does not have bluetooth turned on and the manager is in the proper state. To be sure you can check the SCLFlicManager’s bluetoothState property first. It is recommended that you do not scan for buttons during long periods of time. Background scanning is also quite restricted on iOS so that is also not recommended.

    Declaration

    Objective-C

    - (void)startScan;

    Swift

    func startScan()
  • Stopps the current scan. If the manager is not scanning when this call is made then nothing will happen.

    Declaration

    Objective-C

    - (NSUInteger)stopScan;

    Swift

    func stopScan() -> UInt

    Return Value

    The number of PbFs discovered in total. This includes both public and private PbFs. A discovery callback will not be sent if the PbF is private, but it might still be useful to know if there are any PbFs around, hence the return parameter.

  • All buttons that have ever been discovered by the manager and not manually been forgotten/removed.

    Declaration

    Objective-C

    - (NSDictionary<NSUUID *, SCLFlicButton *> *_Nonnull)knownButtons;

    Swift

    func knownButtons() -> [UUID : SCLFlicButton]

    Return Value

    Dictionary containing the SCLFlicButton objects. The keys are of NSUUID type that represent the buttonIdentifier of the SCLFlicButton instance.

  • This will attempt to completely remove the button from the manager and clear the SCLFlicButton instance. If the button is connected when this method is called then it will also be disconnected first. Remember to clear all your references to this particular button instance so that it properly gets cleared from memory. Only after doing this will you be able to discover the button again when doing a new scan.

    Declaration

    Objective-C

    - (void)forgetButton:(SCLFlicButton *_Nonnull)button;

    Swift

    func forget(_ button: SCLFlicButton)

    Parameters

    button

    The button that you wish to destroy.

  • This will disable all bluetooth communication and disconnect all currently connected buttons and pending connections. You will not be able to do any communication with a Flic/PbF until you call enable.

    Declaration

    Objective-C

    - (void)disable;

    Swift

    func disable()
  • This will enable the bluetooth communication after it has previously been disabled.

    Declaration

    Objective-C

    - (void)enable;

    Swift

    func enable()
  • This will launch the Flic app and allow the user to select a Flic button to assign to this App.

    Declaration

    Objective-C

    - (void)grabFlicFromFlicAppWithCallbackUrlScheme:(NSString *_Nonnull)scheme;

    Swift

    func grabFlicFromFlicApp(withCallbackUrlScheme scheme: String)

    Parameters

    scheme

    This is the callback URL that you have registered in your Plist file and want the Flic app to return the grabbed Flic to. Remember that this is only the scheme name that you have registered, and NOT a full URL.

  • Call this method with the URL returned from the Flic app. A callback will be sent if a button can be created.

    Declaration

    Objective-C

    - (BOOL)handleOpenURL:(NSURL *_Nonnull)url;

    Swift

    func handleOpen(_ url: URL) -> Bool

    Parameters

    url

    This is the full url that was returned from the Flic app.

    Return Value

    If this url can be handled by the flic manager or not.

  • Call this method on significant location changes. This will go through all pending connections and make sure that they are in the proper state. This is needed since we can not rely on Apple to take care of that at all times.

    Declaration

    Objective-C

    - (void)onLocationChange;

    Swift

    func onLocationChange()
  • Calling this method will write the meta data file to be included in the bluetooth log. Any old meta data file will be overwritten. You should call this method just before you intend to upload a bluetooth log as this ensure that all the useful information is included.

    Declaration

    Objective-C

    - (void)prepareBluetoothLogWithMessage:(NSString *_Nullable)message
                                completion:(void (^_Nonnull)(NSURL *_Nullable,
                                                             NSError *_Nullable))
                                               completion;

    Swift

    func prepareBluetoothLog(withMessage message: String?, completion: @escaping (URL?, Error?) -> Void)

    Parameters

    message

    Lets you include additional information that will be written to the log meta data. This could for example be a comment from an end user.

    completion

    Only after a successful completeon is it safe to read out the logging folder.