question

AndreiAppleseed avatar image
AndreiAppleseed asked

Is there a way to terminate the DiscoveryController in order to initialize it again without the app crashing in swift?

Hello,

I have a NavigationController containing a ViewController from where I'm initializing a DiscoveryController and starting a search for custom players. If I go back using the Back button of the Navigation Bar and try to come back in the View Controller that I'm doing the flinging from, the log displays this:

" :I:whisperplay:WhisperplayAdaptor:******** WPStateListener.onInitialized called **************

:I:whisperplay:WhisperplayAdaptor:******** handleWPReady ************** " and the application just stops working, it doesn't crash, it just freezes.

The "discoveryController.close" doesn't seem to be doing anything.

I've tried accessing the deinit function in the FlingViewController when I hit the back button but it's never called. But if I comment out "self.discoveryController.searchPlayer(withId: "amzn.fling.sample.customplayer", andListener: self, andEnableLogs: true)" and try to run the application, the deinit function is called.

I find this really odd since the android version of this iOS app works.

I'm using this in Swift with the help of a AmazonFling pod found on GitHub.

Thank you for your time.

fire tvamazon fling
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Levon@Amazon avatar image
Levon@Amazon answered

Hello,

The code snippet provided here https://cocoapods.org/pods/AmazonFling is good for a single view app. Unfortunately, there can be only one instance of DiscoveryController over the lifetime of the application, for legacy design reasons, making the snippet awkward for your type of app.

If you want to use AmazonFling SDK in a NavigationController based UI, the right design would be to contain the AmazonFling functionality in a class, say AmazonFlingController, whose object should be initialized in the AppDelegate and accessed from individual view controllers. These view controllers should add themselves as delegates to AmazonFlingController while they are visible and receive discovery updates, etc.

Benefits are that you can enable other views to get AmazonFling functionality if needed and enable mocking the Fling functionality to make your app more testable.

We have a task in our backlog to make a sample available for the community. Hope this helps.

Best regards,
Amazon Fling SDK Support Team

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.