Fatal Error: Please set Moltin.clientID

swift

#1

I’m using Moltin in my iOS app.
However when I navigate to my initial Moltin View Controller from your v2 sample, the app crashes and I get this error: “Thread 5: Fatal error: Please set the Moltin.clientID before making a request” on line 62 in my Pods/Moltin/Auth.swift file.

I know my clientID is declared properly and accessible in my AppDelegate, and if I remove the navigation to the VC from my Tab Bar Controller and use this VC as my initial ViewController, then it works no problem.

Can someone explain the process of where the Moltin file accesses the clientID from the AppDelegate, and maybe I can understand how I’m interrupting this request?

Thanks


#2

Hey Eoghan,

This sounds like the lifecycle of your application gets to where you’re calling the Moltin API, before it’s actually set up the Moltin instance with your client ID.

The first place I’d look at is the lifecycle of your application, and why your view controllers are running certain parts of code before your app delegate has returned from application:didFinish.... This may be due to using the Moltin SDK in init or awakeFromNib or something similar, which could get called directly before the app delegate has finished loading, unlike something like viewDidLoad which (usually) only runs when the view controller is ready to be displayed.

Alternatively, a fairly quick fix if you wanted to do so, would be to set the client ID immediately before you run the Moltin call that you want to perform. So whereever you’re calling the Moltin SDK, right before, set the clientID. It’s a static class so you should only need to do it once. However I’d try the other solution first as this could get messy setting the client ID any time you have a life cycle issue.

Hope this helps,
Craig


#3

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.