particle-iot / spark-setup-ios

(DEPRECATED) Spark device setup library - Soft AP Cocoapod/Carthage lib for iOS
Apache License 2.0
19 stars 25 forks source link

Launching on non-root view controllers crashes the phone. #36

Closed crenwick closed 8 years ago

crenwick commented 8 years ago

Launching the spark setup via:

  @IBAction func beginSetupTouched(sender: AnyObject) {
    if let vc = SparkSetupMainController() {
      vc.delegate = self
      self.presentViewController(vc, animated: true, completion: nil)
    }
  }

works fine on the root controller, but when I try to make this action happen on a nested view controller (but still the controller in view), it not only crashes the app but causes the entire phone to restart--losing connection with xcode and making it difficult to debug.

So far, it seems to get to get all the way through the viewDidLoad method before crashing.

crenwick commented 8 years ago

Inside that nested view controller, I can present the SparkSetup on the root controller like so:

if let vc = SparkSetupMainController() {
  vc.delegate = self

  UIApplication.sharedApplication().keyWindow!.rootViewController?.dismissViewControllerAnimated(false, completion: { () -> Void in
    UIApplication.sharedApplication().keyWindow!.rootViewController?.presentViewController(vc, animated: true, completion: nil)
  })
}

This is obviously not the desired behavior I want, as now I need to handle the strange animation of dismissing and presenting two view controllers at the same time, and I also have to handle the logic to bring back the desired (nested) view controller when the SparkSetup completes.

I'm sure this will also cause issues when the SparkSetup dismisses, as the nested view controller is the SparkSetupMainControllerDelegate and not the root view controller.

idokleinman commented 8 years ago

What do you mean works well only on root viewcontroller? You can take the Particle app (Tinker) as an example - it pops up a Setup 'wizard' modal flow which is not on the root VC without any issues. Maybe take a look on that repo as a reference. https://github.com/spark/photon-tinker-ios

crenwick commented 8 years ago

Hmmm. I cloned this fork of the example app and was able to get view controllers working without the crashing bug.

I'll try to dig around more and figure out why this is happening with my app.

idokleinman commented 8 years ago

Great, happy to hear. I'm closing this issue for now, feel free to re-open if necessary or post in our community website if more help is needed https://community.particle.io/c/mobile