我正在使用DJI Mobile SDK和UXSDK示例应用程序(此处找到:https://github.com/dji-sdk/Mobile-UXSDK-iOS)迅速编写一个iOS项目。
我添加了一个带有IBAction getData(_ sender :)的ViewController,它成功地将消息发送到DJI产品。 IBAction完成后,应用程序崩溃,并在AppDelegate.swift中出现EXC_BAD_ACCESS错误
AppDelegate中的错误标志
import UIKit
import Foundation
//To use DJI Bridge app, change `useBridge` to true and add bridge app
IP address in `debugID`
let useBridge = false
let debugIP = "BRIDGE_APP_IP_ADDRESS_HERE"
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,
UISplitViewControllerDelegate {
var window: UIWindow?
open var productCommunicationManager = ProductCommunicationManager()
open var communicationsViewController = CommunicationsViewController()
open var osdkDevice:OnboardSDKDevice?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Start the registration at the launch of the app. This can be retriggered at anytime from the main view.
// DJI App key needs to be registered in the Info.plist before calling this method.
self.productCommunicationManager.registerWithProduct()
return true
}
}
这里是视图控制器。它不是主要的,但可以通过主视图控制器进行导航。
import UIKit
import Foundation
import DJISDK
import DJIUXSDK
class CommunicationsViewController: UIViewController, UITextViewDelegate {
//This is instantiated as a UIViewController as soon as app launches
//The reference in appDelegate is reassigned every time the view launches
//MARK: Properties
@IBOutlet weak var DataDisplay: UITextView!
open weak var appDelegate = UIApplication.shared.delegate as? AppDelegate
//MARK: Methods
override func viewDidLoad() {
super.viewDidLoad()
appDelegate?.communicationsViewController = self
appDelegate?.productCommunicationManager.connectToProduct()
appDelegate?.productCommunicationManager.connectedProduct = DJISDKManager.product()
if (appDelegate?.productCommunicationManager.connectedProduct?.model != nil){
self.DataDisplay.text = (appDelegate?.productCommunicationManager.connectedProduct.model)
}
appDelegate?.osdkDevice = OnboardSDKDevice()
appDelegate?.osdkDevice?.delegate = appDelegate?.osdkDevice
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//MARK: Actions
@IBAction func back(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
@IBAction func getData(_ sender: UIButton) {
//Create 4 bytes of 0's
let data = Data(count: 4)
appDelegate?.osdkDevice?.sendDataFromMobile(toOnboard: data, withCompletion: nil)
//App crashes after exiting scope
}
}
我发现EXC_BAD_ACCESS是由于尝试访问不再可用的内存引起的。我已经仔细检查了所有IBAction和IBOutlets的连接,它们似乎还可以。
这是来自控制台中“ bt”的错误消息
从异常断点开始的控制台和程序集
有人可以帮助我诊断崩溃吗? iOS编程和Swift对我来说都是很新的,因此,如果在此说明中缺少任何内容,请告诉我。谢谢