我有一个技术问题。我已经在我的 swift 项目中集成了 Widevine 库。我已将桥接头链接到 Objective-c 库。问题是图书馆使用:
WViOsApiStatus WV_Initialize(const WViOsApiStatusCallback callback, NSDictionary *settings );
哪里 WViOsApiStatusCallback
是:
typedef WViOsApiStatus (*WViOsApiStatusCallback)( WViOsApiEvent event, NSDictionary *attributes );
在objective-c中,我在.m文件中编写了这段代码:
WViOsApiStatus WidevineCallback( WViOsApiEvent event, NSDictionary *attributes );
@implementation WidevineHelper
-myFunc(){
WV_Initialize(WidevineCallback, configuratioWV);
}
WViOsApiStatus WidevineCallback( WViOsApiEvent event, NSDictionary *attributes )
{
//some code
}
在 Swift 中,我有任何想法来转换目标 c 代码
谢谢安德里亚
____ 附加信息____
class WidevineHelper: NSObject {
typealias WViOsApiStatusCallback = (event: WViOsApiEvent, attributes: NSDictionary? ) -> WViOsApiStatus
var testCallaback : WViOsApiStatusCallback = {(event: WViOsApiEvent, attributes: NSDictionary?) ->WViOsApiStatus in
}
func testfunction(){
var test = WV_Initialize(callback: testCallaback , settings: [NSObject : AnyObject]())
}
}
我试试这个;这似乎是正确的,但编译器说:
/path/WidevineHelper.swift:20:20:无法使用类型为“(回调:WViOsApiStatusCallback,设置:[NSObject:AnyObject])”的参数列表调用“WV_Initialize”
在objective-c 中的widevine 方法声明是:
typedef WViOsApiStatus (*WViOsApiStatusCallback)( WViOsApiEvent event, NSDictionary *attributes );
WViOsApiStatus WV_Initialize(const WViOsApiStatusCallback callback, NSDictionary *settings );
快速移植我快疯了。好难过..