Rakesh, you did not answer my question why you put “productMode = true” in appDelegate - you do this now by calling customizeSetup() (either before or after setting credentials). There are two seperate processes you need to be aware of:
a. the particle device setup
b. the particle login / using cloud etc.
Naturally, before your app can do anything with the particle cloud, you need to have credentials and your device setup to do this. So before your call any functions from part b. above, you need to finish part a. first. Makes sense? From your info it seems you have not gone through the setup process whereby the device is connected to your network, connected to the particle cloud and your app can reach your device. The “customizeSetup()” function is part of the (a) process, not the (b) process. (btw, I am assuming you are using the simple auth process)
In your AppDelegate() get and set your keys as you do now but remove customizeSetup(). Decide which of your viewControllers is going to be displayed first. Now you need to create some logic that determines if your device/app have been setup before or not - this could be a flag that gets set after your made a succesful connection or you can determine if you have authenticated the particle device (look in the SDK for the call) etc. For now, I’d say just hard code something in your viewWillAppear() call so you are not stunned by artifacts of this process. In viewWillAppear() we will just start the device onboarding process with calls to the particle setup sdk
viewWillAppear() {
if let setupController = ParticleSetupMainController() {
customizeSetup()
if let customization = ParticleSetupCustomization.sharedInstance() {
customization.allowSkipAuthentication = false
}
setupController.delegate = self as? UIViewController & ParticleSetupMainControllerDelegate
setupController.modalPresentationStyle = .popover
self.present(setupController, animated: true, completion:nil)
}
}
That will get the onboarding process started. Now this viewcontroller will need to support the particle delegate so add an extension:
extension <your viewcontroller>: ParticleSetupMainControllerDelegate {
func particleSetupViewController( _ controller:ParticleSetupMainController!,
didFinishWith result: ParticleSetupMainControllerResult,
device: ParticleDevice!) {
switch result {
case .succes:
case .loggedIn:
etc. etc.
}
}
}
Once the device/app go through that process, you should see your device attempting to connect to wifi and subsequently to particle cloud. You can verify proper connection by using the particle console. Your app should be connected to Wifi, then to the device’s softAP (the SDK calls will do all that), and subsequently back to your WiFi - it will then ask the particle cloud if the device has been registered and if so, get the device 24 character device ID.
For much more detail on the setup SDK go here; https://docs.particle.io/reference/SDKs/ios/#device-setup-library
For connecting to device once gone through the setup, go here: https://docs.particle.io/reference/SDKs/ios/#ios-cloud-sdk
Also read up on the authentication processes described by particle here: https://docs.particle.io/tutorials/device-cloud/authentication/