整体过程如下图:
核心要点:
初始化 DJI SDK 时的 DJISDKAPPKey 需要绑定到一个付费的开发者账号上(一年 99 刀),否则正式环境发布后很快 SDK 就会初始化失败。
由于我国有着“先进”的管理体制,中国境内所有重量大于 250g 的飞行器必须实名才能飞行。因此如果用户使用时飞行器定位在中国,需要额外的操作:
在 DJI Go 中绑定飞行器到个人。只需绑定一次。类似于车辆的行驶证,这个绑定表明了飞行器的所有者。
使用时需要绑定 DJI 账户,三个月有效期。这样就可以明确三个月内使用这台飞行器的人。当然严格的说,每一次飞行都应该确认是不是这个 DJI 账户对应的人。所以 app 里如果有自己的用户体系,一个用户退出登出后应该也登出 DJI 账户。当然从用户体验来讲,这个操作不做也可以接受。
DJIAppActivationManager 获取绑定状态
激活相关状态由 DJIAppActivationManager 管理:
@interface DJIAppActivationManager : NSObject/*** 绑定状态的回调代理*/@property (nonatomic, weak) id<DJIAppActivationManagerDelegate> delegate;/*** DJIApp 账户绑定状态*/@property (nonatomic, readonly) DJIAppActivationState appActivationState;/*** 飞行器绑定状态*/@property (nonatomic, readonly) DJIAppActivationAircraftBindingState aircraftBindingState;@end@protocol DJIAppActivationManagerDelegate <NSObject>/*** DJIApp 账户绑定状态更新*/-(void)manager:(DJIAppActivationManager *)manager didUpdateAppActivationState:(DJIAppActivationState)appActivationState;/*** 飞行器绑定状态更新*/-(void)manager:(DJIAppActivationManager *)manager didUpdateAircraftBindingState:(DJIAppActivationAircraftBindingState)aircraftBindingState;@end
从 DJISDKManager 获取 appActivationManager :
self.activationState = [DJISDKManager appActivationManager].appActivationState;self.aircraftBindingState = [DJISDKManager appActivationManager].aircraftBindingState;
DJI 账户绑定状态值
typedef NS_ENUM(NSInteger, DJIAppActivationState) {/*** 硬件不支持账户绑定*/DJIAppActivationStateNotSupported,/*** 飞行器定位在中国,需要绑定 DJI 账户*/DJIAppActivationStateLoginRequired,/*** 已经绑定过*/DJIAppActivationStateActivated,/*** 未识别到设备或者设备不是 DJI 产品*/DJIAppActivationStateUnknown = 0xFF,};
那么如何绑定 DJI 账户呢?这个功能由 DJIUserAccountManager 管理:
@interface DJIUserAccountManager : NSObject@property (nonatomic, readonly) DJIUserAccountState userAccountState;@property(nonatomic, readonly, nullable) NSString *loggedInDJIUserAccountName;/*** 登录 DJI 账户。*/-(void)logIntoDJIUserAccountWithAuthorizationRequired:(BOOL)authorizationRequiredwithCompletion:(DJIAccountStateCompletionBlock)completion;/*** 退出当前绑定的 DJI 账户*/-(void)logOutOfDJIUserAccountWithCompletion:(DJICompletionBlock)completion;
登录方法的 authorizationRequired 针对海外用户,表示是否要求登录账户是禁飞区授权账户,如果绑定的账户不是授权账户会再进行一次跳转。日常的场景设置为 false 就可以,只要求普通注册用户。
飞行器绑定状态值
typedef NS_ENUM (NSUInteger, DJIAppActivationAircraftBindingState) {/*** 飞行器绑定要求不确定,飞行器处于飞行限制状态*/DJIAppActivationAircraftBindingStateInitial,/*** 飞行器未绑定,飞行高度会被限制在30米以下,飞行距离在50米内。需要进入 DJI Go 进行绑定*/DJIAppActivationAircraftBindingStateUnbound,/*** 飞行器未绑定,但是此时飞行器没有连接过 DJI Go 或者 DJI SDK 无法连接网络,无法同步是否已经绑定过飞机。*/DJIAppActivationAircraftBindingStateUnboundButCannotSync,/*** 飞行器已绑定*/DJIAppActivationAircraftBindingStateBound,/*** 不用绑定*/DJIAppActivationAircraftBindingStateNotRequired,/*** 硬件不支持飞行器绑定*/DJIAppActivationAircraftBindingStateNotSupported,/*** 未识别到设备或者设备不是 DJI 产品*/DJIAppActivationAircraftBindingStateUnknown = 0xFF,};
AircraftBindingStateInitial
目前只有中国需要绑定飞行器,因此 SDK 或者 DJI Go 需要先检查当前所处的国家地区。如果检查后发现不在中国,状态会更新为 NotRequired。但是如果地区检查失败,飞行器会被置于限制飞行状态。用户需要去 DJI Go 更新绑定状态。
AircraftBindingStateUnboundButCannotSync
如果绑定过,连接 DJI GO 时会把绑定结果同步到飞行器。绑定结果也会同步到服务器,所以如果 SDK 连接网络也可以把绑定结果同步下来。因此这两个条件都不具备时,飞行器的状态是未绑定,但是也许飞行器已经绑定过,只是绑定结果没有同步到飞行器。
这种情况发生在刚开始绑定时飞行器是连接的状态,但是绑定成功之前飞行器的连接断开了,因此绑定结果没有同步到飞行器中。
