Skip to content

Instantly share code, notes, and snippets.

@brien-crean
Last active August 20, 2020 20:51
Show Gist options
  • Save brien-crean/1c5e89c065c79ad11140f389b5bcf9d7 to your computer and use it in GitHub Desktop.
Save brien-crean/1c5e89c065c79ad11140f389b5bcf9d7 to your computer and use it in GitHub Desktop.
Objective C flight controller singleton
@import DJISDK;
@interface RCTBridgeDJIFlightController : RCTEventEmitter<DJIFlightControllerDelegate> {
DJIFlightControllerState *flightControllerState;
NSString *testString;
}
@property(nonatomic, readonly) DJIFlightControllerState *flightControllerState;
@property(nonatomic, readonly) NSString *testString;
+ (id)sharedFlightController;
@end
@implementation RCTBridgeDJIFlightController
DJIFlightControllerState *flightControllerState;
NSString *testString;
@synthesize flightControllerState;
@synthesize testString;
+ (id)sharedFlightController {
static RCTBridgeDJIFlightController *sharedFlightControllerInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedFlightControllerInstance = [[self alloc] init];
});
return sharedFlightControllerInstance;
}
- (id)init {
if (self = [super init]) {
flightControllerState = nil;
testString = @"TEST STRING";
}
return self;
}
-(void)flightController:(DJIFlightController *)fc didUpdateState:(DJIFlightControllerState *)state {
flightControllerState = state;
}
@end
@brien-crean
Copy link
Author

brien-crean commented Aug 20, 2020

class VirtualStickController {
  var flightControllerSharedInstance: RCTBridgeDJIFlightController

  override init() {
      self.flightControllerSharedInstance = RCTBridgeDJIFlightController. sharedFlightController()
  }

  func getFlightControllerState() {
     if let testString = flightControllerSharedInstance.testString {
         print("\(testString)")
     } else {
         print("NOT HERE")
     }

      if let state = flightControllerSharedInstance.flightControllerState {
      print("FLIGHT CONTROLLER STATE: \(state)")
    } else {
      print ("NULL")
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment