[英]Delegate methods not being called in swift class
我正在集成一個跟蹤位置點的 SDK。
SDK 演示應用程序加載了 SDK 框架,然后是一個擴展 SDK 委托的 UIViewController。 當用戶四處移動時,SDK 會調用某些委托函數 - 這些在來自 SDK 提供商的演示應用程序中都可以正常工作。 所有委托回調函數,比如 processStart 都在 TripsViewController 中: UIViewController, TheSDKSwiftDelegate
例子:
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)")
}
}
因此,在 SDK 正常運行期間,它會回調 processStart 方法以提供有關正在發生的事情的信息。
現在,在我自己的應用程序中,我不能在 UIViewController 中擁有這些功能/委托。 我需要將它們放在一個單獨的 Swift 文件中,並從另一個控制器調用這些函數。 當我這樣做時,我的 SDK 會初始化,但 SDK 在運行時不會調用委托方法,而當 UIViewController 擴展委托的所有內容都在時,委托方法會被調用。 只是當我把它放在我自己的 swift 文件中時。
這是我正在做的事情的一小段:
import Foundation
import Capacitor
@objc(TheSDKPlugin)
public class TheSDKPlugin: CAPPlugin {
@objc func SetupSDK(_ call: CAPPluginCall) {
TheSDKPluginWrapper().StartSDK()
}
所以 TheSDKPluginiWrapper().StartSDK() 被調用。
import Foundation
import TheSDKSwift
import Capacitor
class TheSDKPluginWrapper: NSObject, 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)")
}
}
同樣,SDK 初始化成功。 但是現在,SDK 永遠不會調用 TheSDKPluginiWrapper() 中的委托方法。
我如何在整個過程中保留委托,以便在我的 swift 文件中調用 SDK 委托方法,就像當一切都在 UIViewController 中時調用它的方式一樣?
如果您希望委托方法在單獨的文件中,您可以將它們定義為類的擴展:
extension TripsViewController: TheSDKSwiftDelegate {
// TheSDK Delegate callbacks
func processStart(ofDrive startInfo: DriveStartInfo) {
}
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.