July 17, 2018 at 8:29 am #63429
I have a ViewController which handles all activity with BlueTooth NFC read. In the viewDidDisappear of the controller. I want to stop all activities which started up when I entered this screen.
In my viewDidDisappear, I am calling:
I also tried making that flomioSDK variable optional and declaring it nil in viewDidDisappear, however I am still seeing countless logs persist in the console after navigating away from this class:
2018-07-17 13:26:09.215133+0100 App Name[1042:732718] ::discovered peripheral Device name -AlphaNumericText
How can I be sure to stop all unnecessary battery consumption with the flomioReader and bluetooth once I leave this page.
lazy var flomioSDK : FmSessionManager = FmSessionManager()
lazy var defaultConfiguration: FmConfiguration = FmConfiguration()
My configuration in viewDidLoad is as follows:
defaultConfiguration = FmConfiguration()
defaultConfiguration.deviceType = .kFloBlePlus
defaultConfiguration.transmitPower = .highPower
defaultConfiguration.scanSound = true
defaultConfiguration.scanPeriod = 1000
defaultConfiguration.powerOperation = .autoPollingControl
defaultConfiguration.allowMultiConnect = false
self.flomioSDK = FmSessionManager.init(configuration: self.defaultConfiguration)
self.flomioSDK.delegate = selfJuly 17, 2018 at 9:59 am #63430
I am seeing some very strange behaviour.
I have the ViewController which performs the scans. I am passing in a type property into this screen so I know whether to read data from the tag or write to the tag.
Each work fine on standalone. But if I go into this screen and do a write, navigate away and then come back passing in the read variable this time, the write is still triggered. I can see in my override prepareFor segue, that I am passing the correct variable.
It seems whichever operation I carry out first, I cannot then perform the other operation thereafter.
Even if I go into this screen to do a NFC read, then navigate away from the screen, and put a tag near the Flomio reader, the delegate method in the screen which has been popped away is still triggered?
I think this is related to the fact that I need to deinit the flomioSDK in the ViewDidDisappear. I tried calling stopReaders in viewDisappear and startReaders in the viewDidAppear, but it doesn’t seem to work. Once stopReaders is called, my delegate methods are no longer triggered, even after re-calling startReaders.
I thought by only initialising the Flomio object in one particular screen should limit the scope to that screen.
This stop/start is key for me. Any help would be appreciated on the best practise approach for this. This is the last piece to getting a fully working solution.
RoseanneJuly 17, 2018 at 12:04 pm #63432
You should not initialize the FlomioSDK more than once per session of the app. You should initialize it once and keep a reference to it when you want to interact with it.
You can use
powerOperation = .bluetoothConnectionControlto change startReader and stopReader to control bluetooth scanning.
I can’t understand the reading and writing issue, but if you reinitialize the flomioSDK every time the page is opened, this would cause issues.
Let me know if you have any more questions,
ScottJuly 17, 2018 at 2:04 pm #63433
I am only initialising in the appDelegate now and all the issues described seem to be resolved.
You must be logged in to reply to this topic.