如何解决使用cordova CDVInvokedUrlCommand [Swift 5]的Swift致命错误
我正在尝试在 Swift 中重用现有的目标函数(ImagePicker 的逻辑)。当我使用 Cordova 传入请求中的“CDVInvokedUrlCommand”时,我遇到了致命错误问题。
来自 Cordova 的 Swift 传入请求:
@objc func triggerPhotoGallery(_ command: CDVInvokedUrlCommand){
print(command.callbackId!)
Test1.processExistingFunc(command)
}
目标 C
+ (void)processExistingFunc:(CDVInvokedUrlCommand *)command{
cr_command = command;
UIImagePickerController *imgPickerCObj;
imgPickerCObj = [[UIImagePickerController alloc] init];
imgPickerCObj.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
......
.....
}
+(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
// Sending result back to Swift
TestClass* testClass = [[TestClass alloc] init];
[testClass cbSwiftFunc:cr_command: finalresult];
}
回调到 Swift
@objc(cbSwiftFunc::)
public func cbSwiftFunc(_ command: CDVInvokedUrlCommand,result:string) {
print(" :: cbSwiftFunc ::")
print(command.callbackId!)
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK,messageAs: result)
print(pluginResult)
// This line of code creates fatal error
**commandDelegate!.send(pluginResult,callbackId: command.callbackId!)**
}
错误:
Fatal error: Unexpectedly found nil while unwrapping an Optional value: file Test/TestFunction.swift,line 522
2021-03-22 09:15:02.110735+0800 XXXX[295:30269] Fatal error: Unexpectedly found nil while unwrapping an Optional value: file Test/TestFunction.swift,line 522
线程 1:致命错误:在展开可选值时意外发现 nil
我的观察:
- 我已检查传入回调 ID 和传出呼叫回调 ID 相同。
- 结果不为空,仍然抛出意外发现为零
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。