Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get device id from setup #42

Closed
kyle-ssg opened this issue Mar 8, 2016 · 15 comments
Closed

Get device id from setup #42

kyle-ssg opened this issue Mar 8, 2016 · 15 comments
Labels

Comments

@kyle-ssg
Copy link

kyle-ssg commented Mar 8, 2016

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
Copy link
Contributor

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
Copy link
Author

kyle-ssg commented Mar 8, 2016

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
Copy link
Contributor

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

@kyle-ssg
Copy link
Author

kyle-ssg commented Mar 9, 2016

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

@kyle-ssg
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

Let me know how it goes

@kyle-ssg
Copy link
Author

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
Copy link
Author

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
Copy link

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
Copy link

@kyle-ssg Any help possibly?

@shaskins
Copy link

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
Copy link

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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants