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

Get device id from setup #42

Closed kyle-ssg closed 8 years ago

kyle-ssg commented 8 years ago

Hey, this is less of an issue more of a question. I'm looking to port this to a react native app. I've got the setup working however I'm wondering if I can get the connected device id as part of any callback? I have next to no objective c experience so I'm probably missing something :). I've written a simple bridge as follows:

//  RNParticle.m
#import "SparkSetup.h"
#import "RNParticle.h"
#import "AppDelegate.h"

@implementation RNParticle
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(open)
{
  SparkSetupMainController *setupController = [[SparkSetupMainController alloc] initWithSetupOnly:YES];
  AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  [delegate.window.rootViewController presentViewController:setupController animated:YES completion:nil];
}
@end
idokleinman commented 8 years ago

Sure, there you go:

You can get an active instance of SparkDevice by making your viewcontroller conform to protocol when setup wizard completes.

-(void)SparkSetupViewController:(SparkSetupMainController *)controller didFinishWithResult:(SparkSetupMainControllerResult)result device:(SparkDevice *)device;

This method will be called. If (result == SparkSetupMainControllerResultSuccess) the device parameter will contain an active SparkDevice instance. You can get its device-id by just probing device.id

Good luck

kyle-ssg commented 8 years ago

Thanks so much for the quick response! I have a feeling I tried this however started getting keychain issues.. Again Objective C is completely new to me.. Will have to try again when i get my hands on a photon. From what I understand then I just add this to my app delegate ?


@interface AppDelegate() <ReactNativeAutoUpdaterDelegate>
@end
@implementation AppDelegate
-(void)SparkSetupViewController:(SparkSetupMainController *)controller didFinishWithResult:(SparkSetupMainControllerResult)result device:(SparkDevice *)device {
    //emit event with device.id 
}

.....
idokleinman commented 8 years ago

Looks good. Investigating the keychain issue. btw, you can always go the Swift way if Obj-C feels weird to you

kyle-ssg commented 8 years ago

Hi again. I'm getting SparkSetupResultSuccessUnknown as the result and device is null, however the device connected successfully.

kyle-ssg commented 8 years ago

Hi, could you perhaps shed any light on this? I imagine it could either be due to my device in particular, or perhaps the device doesn't return with initWithSetupOnly:YES

idokleinman commented 8 years ago

This means that the cloud detected the device as offline just after finishing setup and could not generate an instance. Is it happening all the time?

kyle-ssg commented 8 years ago

Seems to be happening every time yes, I'll try on my WIFI at home perhaps in that case as it takes quite a bit longer to connect at work.

idokleinman commented 8 years ago

Let me know how it goes

kyle-ssg commented 8 years ago

Hi again, it seems to still happen when tethering to my phone. Eventually I'll be working with a chipset that goes dormant as soon as it successfully connects to the network in order to save battery, I imagine this approach won't work here.

Upon inspection it seems getDeviceID is successfully retrieving a detectedDeviceID during setup. Is there a way I can simply pass that to the setupDidFinishObserver ?

Edit: Looking in checkForInternetConnectivity, it looks like it finishes with SparkSetupResultSuccessUnknown if self.needToClaimDevice is false.. Is this not because I'm using initWithSetupOnly:YES?

kyle-ssg commented 8 years ago

Ended up implementing didFinishWithResult:(SparkSetupMainControllerResult)result deviceID:(NSString *)deviceID

returns deviceID in either success or unknown, this shall suffice for what I need.. Thanks!

KillerGasy commented 8 years ago

Hey Kyle,

Would you mind helping me integrate the set up library with React Native?

Having some issues, I also have little to no knowledge of Objective-C.

Thanks in advance,

KillerGasy

KillerGasy commented 7 years ago

@kyle-ssg Any help possibly?

shaskins commented 7 years ago

Which part do you need help with? You basically just need to include the particle iOS sdk in your xcode project with either cocoapods or carthage, and then you build a custom class as seen on the OP to create a wrapper for it. Import it in your javascript, and you can then access it.

You can read about creating and using native components here: https://facebook.github.io/react-native/docs/native-components-ios.html

KillerGasy commented 7 years ago

I have been able to do that part. The main part in which I am having trouble is getting the ID from a successful connection and giving it to the React-Native side of the application. @steve-haskins

anigo333 commented 7 years ago

Pining this thread as i have the same issue using the same parameters as @kyle-ssg had and we are using swift. So does it mean we need to override the default library behavior as well?