Swift & RemoteController Delegate
已完成I can get Remote Controller joystick values on Xcode using Objective-C with the codes below. What about doing the same using Swift? is there an example in Swift like getting rightStick.horizontalPosition. Thank You.
//
// RCTest.m
// DJISdkDemo
//
// Created by Mustafa Akkuzu on 21.10.2021.
// Copyright © 2021 DJI. All rights reserved.
//
#import "RCTester.h"
#import <DJISDK/DJISDK.h>
@interface RCTester () <DJIRemoteControllerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *leftH;
@property (weak, nonatomic) IBOutlet UILabel *rightV;
@property (weak, nonatomic) IBOutlet UILabel *leftV;
@property (weak, nonatomic) IBOutlet UILabel *rightH;
@property (weak, nonatomic) IBOutlet UILabel *myMessage;
@property(nonatomic, weak) DJIBaseProduct* product;
@end
@implementation RCTester
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[DJISDKManager hasSDKRegistered];
DJIRemoteController* rc = [self fetchRemoteController];
if (rc) {
rc.delegate = self;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)remoteController:(DJIRemoteController *)rc didUpdateHardwareState:(DJIRCHardwareState)state
{
self.rightH.text = [NSString stringWithFormat:@"%d", state.rightStick.horizontalPosition];
self.rightV.text = [NSString stringWithFormat:@"%d", state.rightStick.verticalPosition];
self.leftV.text = [NSString stringWithFormat:@"%d", state.leftStick.verticalPosition];
self.leftH.text = [NSString stringWithFormat:@"%d", state.leftStick.horizontalPosition];
}
-(DJIRemoteController*) fetchRemoteController {
if (![DJISDKManager product]) {
return nil;
}
if ([[DJISDKManager product] isKindOfClass:[DJIAircraft class]]) {
return ((DJIAircraft*)[DJISDKManager product]).remoteController;
}
return nil;
}
@end
-
It`s the same, you could also use the swift language to get the aircraft component object, and there`s a simple swift language sample( but there`s no virtual stick part, you should do the program by yourself if you needed ), below link is for your reference. https://www.github.com/dji-sdk/Mobile-SDK-iOS/tree/master/Sample%20Code/SwiftSampleCode/DJISDKSwiftDemo https://www.github.com/dji-sdk/Mobile-SDK-iOS/blob/master/Sample%20Code/SwiftSampleCode/DJISDKSwiftDemo/Camera/fpv/CameraFPVViewController.swift Like as below, use the swift language to get the camera object. ![](https://djisdksupport.zendesk.com/attachments/token/dqkUSl7nkjhrG7wI4MacOI4EW/?name=inline1179620558.png)
请先登录再写评论。
评论
3 条评论