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

SparkSetupMainController failing due to missing bundle #32

Closed JSchaenzle closed 8 years ago

JSchaenzle commented 8 years ago

When I try to create an instance of SparkSetupMainController the following line throws an exception: NSBundle *bundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"SparkSetup" withExtension:@"bundle"]];

The exception seems to indicate that the bundle is nil. `-[NSBundle initWithURL:]: nil URL argument"``

I am using Cocoapods to load the Spark-Setup dependency. I have tried using the latest released cocoapod (0.3.2) and the head of master and have the same problem with both.

idokleinman commented 8 years ago

Strange. Can you take a look at this example project: https://github.com/spark/spark-setup-ios-example

as a reference on how to use the SparkSetup lib - maybe you've done something wrong. let me know if that works for you

JSchaenzle commented 8 years ago

The example project works (although I had to replace all the println calls with print to compile it with xcode7).

I've been comparing the items in the Build Phases between my project and the example and I noticed that the example project contains a bunch of items under the 'Copy Bundle Resources' section including fonts and the main storyboard. When I look at my project I don't have any of the same items listed in that section, except for a LaunchScreen.xib. I have other images and things that I added to my project.

Do you know how those items got added to that build phase? I would assume that it's supposed to be taken care of by Cocoapods. Do you know what would cause the the resources to not be added for me?

One other question. I have been trying to use Carthage more and more for dependencies. Do you know if the SparkSetup library can be built as a framework and imported using Carthage instead of Cocoapods?

JSchaenzle commented 8 years ago

Oh by the way, I also had to change the angle brackets around the header files to quotes, in SparkSetup.h, in order to compile my project. Not sure if that is also telling of a setup problem...

idokleinman commented 8 years ago
  1. Yea, project needs updating to Swift 2.1/iOS9.1/Xcode 7.1 - shouldn't be a big issue (XCode got 'convert to modern swift' auto refactoring option)
  2. I am not sure about the copy bundle resources issue - what I'd recommend is removing 'SparkSetup' and/or 'Spark-SDK' from PODFILE running pod install and then re-adding it and running pod install again - I found that it solves those kind of issues usually. Be sure you have the latest cocoapods version (gem install cocoapods)
  3. Carthage - I want to look into that, It is certainly in my backlog, I am sure Cloud SDK can be compiled as a framework, device setup should too (but might be more tricky because of the resources). Feel free to try it out yourself and send a PR if you manage to get it done. I think it shouldn't be too complicated. It'll be awesome to have Carthage support.
  4. Brackets vs quotes - that's weird. Did you configure the bridging headers correctly? Is your project swift/Obj-C?
andrewmunsell commented 8 years ago

I've been running into the same issue but have fixed it for myself. One of the problems is that in my Swift project, I've turned on CocoaPods use_frameworks! to enable the use of some external Swift libraries. Because of this, the bundle isn't properly located (see the announcement for CocoaPods 0.36 where this change was made: http://blog.cocoapods.org/CocoaPods-0.36/)

I'll have to verify that this is the change that fixed the problem (I've messed with the setup code a bit now trying to get it to work), but you can change [NSBundle mainBundle] to [NSBundle bundleForClass: [self class]] and ensure that the "Copy Bundle Resources" Build Phase of the SparkSetup framework includes SparkSetup.bundle so that the actual bundle is found (turns out this is not needed).

Once I've done reproducing the issue with a minimal project, I can submit a pull request.

JSchaenzle commented 8 years ago

Just wanted to say I discovered this same thing earlier tonight. I removed use_frameworks! from my Podfile and that fixed the issue. Mine is also a swift/obj-c project but I'm actually not using Cocoapods to pull in any frameworks (I'm using Carthage for that) so it looks like I don't need the use_frameworks! flag.

I am glad to hear you fixed this though. Thanks!

idokleinman commented 8 years ago

PR merged, thanks!

crenwick commented 8 years ago

Is there a demo of this working?

I can get my project to build and go on a device, but I cannot successfully create an archive with use_frameworks!.