This tutorial is designed for you to obtain a better understanding of the DJI Remote Logger Tool. It will teach you how to use it for showing application log messages on a simple webpage.
You can download the tutorial's final sample project from this Github Page.
In order to use the DJI Remote Logger Tool, you should have two parts: DJI iOS Mobile SDK and Server Script. The remote logger feature is integrated inside the SDK, you can use this feature in your application directly. For the server part, there are two connection modes showing below:
You can connect your iOS device and Mac to the same WiFi network or connect to a local wireless connection created on your Mac too. This would be helpful when you test your application outside without internet connection.
If you don't have iOS device, you can use your Xcode Simulator too. Using the url string like http://localhost:4567 can work well with the server script.
You can get the server script from the Server folder from the Github Page. Please follow the steps below to setup the server:
./run_log_server.bash
If everything goes well, you should see something similar to the following screenshots:
If you meet the following error, you may need to install the command line developer tools:
Run this command: xcode-select -install
, then you will see the following dialog:
After installing it, try ./run_log_server.bash
command again. Problem should be solved.
If you meet the following error, you may need to install ruby:
Run this command: sudo brew install ruby
, after installing ruby successfully, try ./run_log_server.bash
command again. Problem should be solved.
For other issues, please check the two problems above.
For DJI SDK mobile application used in China, it's required to activate the application and bind the aircraft to the user's DJI account.
If an application is not activated, the aircraft not bound (if required), or a legacy version of the SDK (< 4.1) is being used, all camera live streams will be disabled, and flight will be limited to a zone of 100m diameter and 30m height to ensure the aircraft stays within line of sight.
To learn how to implement this feature, please check this tutorial Application Activation and Aircraft Binding.
If you are not familiar with the process of installing DJI SDK in your Xcode project, please check the Github source code and this tutorial: Importing and Activating DJI SDK in Xcode Project for details.
1. Implement the DJISDKManagerDelegate protocol method in the ViewController.m file's extension part. Then create a new method named registerApp and invoke it in the viewDidAppear method as shown below:
- (void)registerApp |
Note: If you don't know how to apply as a DJI developer and get the App Key, please refer to the Get Started.
2. Next, let's implement the DJISDKManagerDelegate method as shown below:
- (void)appRegisteredWithError:(NSError *)error |
The delegate method above gets called when the app is registered. If the registration is successful, we can call the +(void) enableRemoteLoggingWithDeviceID: (NSString * _Nullable) deviceID logServerURLString: (NSString*) url;
class method of DJISDKManager to enable remote logging feature of the SDK by passing the deviceID parameter and url parameter, which you can get from the server script command line.
Note:
1. The deviceID is used to distinguish different iOS devices. You can show log messages from different iOS devices on the same webpage.
2. The url is shown in the command line like this:
3. Build and run the project in Xcode. If everything is OK, you will see a "Register App Successed!" alert once the application loads.
Go to Main.storyboard and drag a UIButton to the center of the view, name it "Log SDK Version" and create an IBAction method, named - (IBAction)logSDKVersionButtonAction:(id)sender
for it in the ViewController.m file. Implement the IBAction method shown as below:
- (IBAction)logSDKVersionButtonAction:(id)sender { |
In the code above, we use DJILogDebug Macro to show SDK's version info. There are five types of log Macros, you can use them for different purposes:
Finally, build and run the project, press the button, you may be able to see the SDK version log message on the webpage like the followings:
Note: If you cannot see the logs on webpage and got the log message in the Xcode Console like this:
You can solve this issue by adding the following item, "App Transport Security Settings" in the Info.plist file and modify the "Allow Arbitrary Loads" BOOL value to YES:
Furthermore, the DJI Remote Logger Tool supports multiple iOS devices logging, you can assign different Device IDs for different iOS devices in the +(void)enableRemoteLoggingWithDeviceID:logServerURLString:
class method of DJISDKManager.
Also you can use url content filter for specific device's log like this:
http://10.81.9.167:4567/?filter=113
.
Congratulations! You've learned how to use DJI Remote Logger Tool to show log messages of your application using DJI Mobile SDK. With DJI Remote Logger Tool, you can developer and debug your application with DJI Mobile SDK more efficiently. Hope you enjoy this tutorial, Thanks!