问题描述
我正在集成一个跟踪位置点的SDK。
SDK演示应用程序已加载SDK框架,然后加载了UIViewController来扩展SDK委托。当用户四处移动时,SDK会调用某些委托函数-这些功能在SDK提供程序的演示应用程序中都可以正常运行。所有委托回调函数(例如processstart)都位于TripsViewController中:UIViewController,TheSDKSwiftDelegate
示例:
--recursive
因此,在SDK正常运行期间,它随后会回调processstart方法以提供有关所发生情况的信息。
现在,在我自己的应用程序中,UIViewController中没有这些功能/代理。我需要将它们放在单独的Swift文件中,然后从另一个控制器调用函数。当我这样做时,我的SDK会初始化,但SDK运行时不会调用委托方法,而当UIViewController上的所有内容都在扩展委托时,都会调用委托方法。只是当我将其放入自己的快速文件中时。
这是我正在做的一小段:
import TheSDKSwift
final class TripsViewController: UIViewController,TheSDKSwiftDelegate {
...
TheSDKSwift.setup(with: configuration,delegate: self,completionHandler: {success,error in
if success {
successBlock()
} else {
failureBlock(error)
}
})
...
// TheSDK Delegate callbacks
func processstart(ofdrive startInfo: DriveStartInfo) {
self.driveStatusLabel.text = "Driving"
if self.isAccidentEnabled() {
self.mockAccidentButton.isEnabled = true
}
let dateString = DateFormatter.shortStyleFormatter.string(from: Date(timeIntervalSince1970: TimeInterval(startInfo.startTimestamp/1000 )))
notificationmanager.displayNotification(message: "Trip Started: \(dateString)")
}
}
因此调用了SDKPluginiWrapper()。StartSDK()。
import Foundation
import Capacitor
@objc(TheSDKPlugin)
public class TheSDKPlugin: CAPPlugin {
@objc func SetupSDK(_ call: CAPPluginCall) {
TheSDKPluginWrapper().StartSDK()
}
同样,SDK成功初始化。但是现在,SDK从未在TheSDKPluginiWrapper()中调用委托方法。
我如何始终保留委托,以便在我的swift文件中调用SDK委托方法,就像在UIViewController中所有内容都被调用一样?
解决方法
如果要将委托方法放在单独的文件中,则可以将它们定义为类的扩展:
extension TripsViewController: TheSDKSwiftDelegate {
// TheSDK Delegate callbacks
func processStart(ofDrive startInfo: DriveStartInfo) {
}
...
}