【问题标题】:PhoneGap (Cordova) CDVCommandDelegate is Nil, How Can I Get Valid Object?PhoneGap (Cordova) CDVCommandDelegate 为 Nil,如何获取有效对象?
【发布时间】:2015-02-12 07:05:28
【问题描述】:

我们正在使用 PhoneGap (Cordova) 构建我们的应用程序。

但是我有一个单独的 Swift 项目,我在其中使用 Swift 进行所有本机编码,然后我们将 Swift 代码复制到由 PhoneGap 构建的 .xcodeproj 中。

为了让生活更轻松,我正在将 Cordova “安装”到我的 Swift 项目中,这样我就可以模仿 Cordva 构建的应用程序中发生的调用。基本上我希望能够调用 CDVPluginResult 并从 CDVCommandDelegate 发送该结果。

我已成功安装 Cordova,但现在很难让 1 件事正常工作:我的 CDVCommandDelegate 始终为零。

这是我尝试将图像作为 base64 字符串发送的代码:

//custom CDVPlugin class that I called CDVPluginDelegate
let _singleton = CDVPluginDelegate()

//handles all CDVPlugin delegation tasks
class CDVPluginDelegate: CDVPlugin
{
    class var SINGLETON:CDVPluginDelegate
    {
        return _singleton
    }
}

//getting a picture and returning it 
 //pass image to phonegap
        var imageData = UIImagePNGRepresentation(image)
        var base64:String = imageData.base64EncodedStringWithOptions(nil)
        var cdvResult:CDVPluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAsString: base64)
        println(CDVPluginDelegate.SINGLETON.commandDelegate)//PRINTS nil
        CDVPluginDelegate.SINGLETON.commandDelegate.sendPluginResult(cdvResult, callbackId: "imageSent")//crashes because command delegate is nil

如何正确创建/分配此 CDVPluginCommand 委托?

【问题讨论】:

    标签: ios cordova swift phonegap-plugins


    【解决方案1】:

    我不知道为什么,但您只能在使用 Cordova 构建时获得有效的命令委托。如果您从 Cordova 进行构建,则命令委托是有效的,否则(如果您将 Cordova 作为现有应用程序的“插件”安装)它将为零。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多