From a6cbfed0be9eb34cc04789551898fb744ef01c7a Mon Sep 17 00:00:00 2001 From: Zach Dennis Date: Tue, 20 Nov 2018 22:31:16 -0500 Subject: [PATCH 1/2] Add support for starting the devise setup with setupOnly --- src/particle.android.ts | 3 ++- src/particle.common.ts | 2 +- src/particle.ios.ts | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/particle.android.ts b/src/particle.android.ts index 3df32ea..2f7f80d 100644 --- a/src/particle.android.ts +++ b/src/particle.android.ts @@ -175,7 +175,7 @@ export class Particle implements TNSParticleAPI { return io.particle.android.sdk.cloud.ParticleCloudSDK.getCloud().getAccessToken(); } - public startDeviceSetupWizard(): Promise { + public startDeviceSetupWizard(o?: { setupOnly: boolean; }): Promise { return new Promise((resolve, reject) => { // note that since we _have_ to return an intent, the activity is relaunched, so there's some state juggling required in the app const intent = AndroidApp.foregroundActivity.getIntent(); @@ -191,6 +191,7 @@ export class Particle implements TNSParticleAPI { }); } + public getDeviceSetupCustomizer(): any { // stub for getDeviceSetupCustomizer } diff --git a/src/particle.common.ts b/src/particle.common.ts index 0dd1236..e1e95ee 100644 --- a/src/particle.common.ts +++ b/src/particle.common.ts @@ -87,7 +87,7 @@ export interface TNSParticleAPI { listDevices(): Promise>; - startDeviceSetupWizard(): Promise; + startDeviceSetupWizard(o?: { setupOnly: boolean; }): Promise; getDeviceSetupCustomizer(): any; diff --git a/src/particle.ios.ts b/src/particle.ios.ts index 4e33184..4dfb05e 100644 --- a/src/particle.ios.ts +++ b/src/particle.ios.ts @@ -234,9 +234,12 @@ export class Particle implements TNSParticleAPI { this.eventIds.delete(prefix); } - public startDeviceSetupWizard(): Promise { + public startDeviceSetupWizard(o?: { setupOnly: boolean; }): Promise { + if (!o) { + o = { setupOnly: false }; + } return new Promise((resolve, reject) => { - const setupController = ParticleSetupMainController.new(); + const setupController = ParticleSetupMainController.new().initWithSetupOnly(o.setupOnly); this.wizardDelegate = ParticleSetupControllerDelegateImpl.createWithOwnerAndCallback(new WeakRef(this), (result: boolean) => resolve(result)); setupController.delegate = this.wizardDelegate; UIApplication.sharedApplication.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(setupController, true, null); From 84cb706d0532ce1d082998d151824ed2a9d44f2d Mon Sep 17 00:00:00 2001 From: Zach Dennis Date: Fri, 23 Nov 2018 11:32:04 -0500 Subject: [PATCH 2/2] Use the constructor override rather than chanining. The previous code caused a memory error and raised an EXC_BAD_ACCESS shortly after calling this method. --- src/particle.ios.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/particle.ios.ts b/src/particle.ios.ts index 4dfb05e..e911fb7 100644 --- a/src/particle.ios.ts +++ b/src/particle.ios.ts @@ -239,7 +239,7 @@ export class Particle implements TNSParticleAPI { o = { setupOnly: false }; } return new Promise((resolve, reject) => { - const setupController = ParticleSetupMainController.new().initWithSetupOnly(o.setupOnly); + const setupController = new ParticleSetupMainController({setupOnly: true}); this.wizardDelegate = ParticleSetupControllerDelegateImpl.createWithOwnerAndCallback(new WeakRef(this), (result: boolean) => resolve(result)); setupController.delegate = this.wizardDelegate; UIApplication.sharedApplication.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(setupController, true, null);