How to auto-apply a lens at startup?
Hello, Currently attempting to apply a lens programmatically on iOS, but I'm struggling to find out how to do so appropriately. In most of my attempts, the app will crash if I try to apply the lens too early (at startup). If I put in a delay for a few seconds, there is no problem.
The result of cameraController.lenses.repository.lens(...) is nil until a certain point. But I can't seem to find out where the appropriate place in the startup I can safely grab my lens.
There are notes about only doing so after setting an observer, and I have tried to do that.
Meanwhile the app works fine unless I condition poor network status, in which case it will crash. I will build graceful error handling, but I still want to
1) Apply a lens properly
and
2) apply the lens as early as possible within the startup.
Comments
-
@Vincent Frascello Thanks for the detailed post. Very helpful. Let me look into this with our eng team for you. Could you also share these following details when you get the chance:
- Platform : iOS / Android
- CameraKit SDK version
- Screenshots / Screen Recordings of Issues where appropriate. I,e Lens Performance Issue
Just fyi - our team is out of office for the holidays so please expect up until the second week of January to hear back from them. I'll do my best to see if I can get you a solution sooner wherever possible
0 -
Thanks @Vincent Frascello! You can apply a lens just after it is in the repository. But how does one know when that is? In the iOS SDK, you seen when that is by conforming a class to
LensRepositoryGroupObserver
and implementingrepository(_:didUpdateLenses:forGroupID:)
. This method lets conformers get notified when Lenses in a group have been updated. In your case, you will want to apply the Lens after the first update.The iOS sample app has a nice example of this in
CameraController
.0