ParticleSetup iOS fails to claim device

I created my own iOS app that uses the particle-iot/particle-setup-ios pod.

Out firmware is running in MANUAL mode so we’re taking care of wifi and cloud connections.

My app is failing to claim the device correctly. It’s failing in step 4: checkDeviceIsClaimed.
Here’s the logic reponsible for the onboarding, you can see step 4 in the following file:

After it fails, I put the photon in listening mode again, and it works correctly. Any ideas why this is happening?
Has anyone found a complete explanation about Particle.connect() ? Does it block the main thread()? Does it block it until it connects to the cloud? What happens if that’s called with no wifi credentials yet?

Hi gpiffaretti.fsstudio,

I’d like to get the opinion of our resident iOS expert, @Raimis on this.

It’s hard to tell what is happening just by this information alone. We have recently addressed one issue in our SDK that might have caused this if you have many devices on your account. How many devices do you have on the account you are using to claim new devices? If this is happening with an account that only has few devices, can you please confirm that you are signed in from your mobile app to Particle Cloud.

Found the issue.
Looks like our firmware is taking longer than expected to get online and connect to the cloud.

So the iOS app was failing when it attempted to do:

[[ParticleCloud sharedInstance] claimDevice:self.deviceID completion:^(NSError *error) {
        NSLog(@"Error claiming device");
        [self setCurrentConnectionProgressStateError:YES];
        NSLog(@"FinishSetupWithResult: ParticleSetupMainControllerResultFailureClaiming");
        [self finishSetupWithResult:ParticleSetupMainControllerResultFailureClaiming];
    } else ...

It was falling in that IF statement.
That request (unlike the others) has no retry logic, so it sent the user directly to the final screen with the Failure result.
So I had to replace with the following logic in order to the claim request again:

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self checkDeviceIsClaimed];

This is a simplified version and doesn’t have a counter for number of retries, but it proves the point.
It’s working now, hope that was it.

Thanks for the fast reply!

1 Like