[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

api[dji-ios] 11 Delegates

"	DJISDK Delegates
"

NSObject
	subclass: #DJISDKManagerDelegate
	instanceVariableNames: ''
	classVariableNames: #Current
	category: #Delegates!
DJISDKManagerDelegate comment: '
	Manage the updated registration status and the change of connected product.
	https://developer.dji.com/api-reference/ios-api/Components/SDKManager/DJISDKManager.html#djisdkmanager_protocol_inline'!

! DJISDKManager class methodsFor: #registration !
registerApp
	" Register the application if it is required.
	Returns true if the registration has been started.
	"

	self hasSDKRegistered ifFalse: [
		DJISDKManagerDelegate registerApp.
		^true
	].
	^false! !

! DJISDKManagerDelegate class methodsFor: #objC !
implementation
	" Private - Return the implementation literal of the receiver. "

	^(#outlets -> #())
	,(#methods -> #(
		#(appRegisteredWithError: 'void id')
		#(productConnected: 'void id')
		#(productDisconnected 'void')
		#(componentConnectedWithKey:andIndex: 'void id id')
		#(componentDisconnectedWithKey:andIndex: 'void id id')
		))! !

! DJISDKManagerDelegate class methodsFor: #instantiation !
current
	" Returns the instance in use. "

	Current isNil ifTrue: [ Current := self instance ].
	^Current! !

! DJISDKManagerDelegate class methodsFor: #example !
registerApp
	" Sample - Register application. "

	^self	registerApp: [ self print: '// Registration success' ]
		onError: [:err| self print: '// Error ',err description ]! !

! DJISDKManagerDelegate class methodsFor: #example !
registerApp: successBlock onError: onErrorBlock
	" Sample - Register application. "

	| sample |
	sample := self current.
	sample	when: #appRegisteredWithError: do: [:err|
			sample removeActionsForEvent: #appRegisteredWithError:.
			onErrorBlock evaluateWith: err
		];
		when: #appRegistered do: [
			sample removeActionsForEvent: #appRegistered.
			successBlock evaluate
		].
	DJISDKManager registerAppWithDelegate: sample! !

! DJISDKManagerDelegate class methodsFor: #events !
constructEventsTriggered
	" Private - Return the events managed by instances of the receiver. "

	^#(	appRegistered appRegisteredWithError:
		productConnected: productDisconnected
		componentConnectedWithKey:andIndex:
		componentDisconnectedWithKey:andIndex:
	) ,super constructEventsTriggered! !

! DJISDKManagerDelegate methodsFor: #objC !
appRegisteredWithError: error
	" Private - Delegate method after the application attempts to register. "

	<objC: method>
	error isNil ifTrue: [
		^self triggerEvent: #appRegistered
	].
	self triggerEvent: #appRegisteredWithError: with: NSError @ error! !

! DJISDKManagerDelegate methodsFor: #objC !
productConnected: product
	" Private - The product is connected.
	The product is nil if the USB link or WiFi link between the product and phone is disconnected. "

	<objC: method>
	self triggerEvent: #productConnected: with: DJIBaseProduct @ product! !

! DJISDKManagerDelegate methodsFor: #objC !
productDisconnected
	" Private - The product is disconnected. "

	<objC: method>
	self triggerEvent: #productDisconnected! !

! DJISDKManagerDelegate methodsFor: #objC !
componentConnectedWithKey: key andIndex: index
	" Private - The component is connected "

	<objC: method>
	self	triggerEvent: #componentConnectedWithKey:andIndex:
		with: key with: index! !

! DJISDKManagerDelegate methodsFor: #objC !
componentDisconnectedWithKey: key andIndex: index
	" Private - The component is disconnected "

	<objC: method>
	self	triggerEvent: #componentDisconnectedWithKey:andIndex:
		with: key with: index! !