开发者

C-callback without class pointer

开发者 https://www.devze.com 2023-02-14 18:38 出处:网络
In my app I use the JavaScriptCore API to install a JS function in the WebView context with a C callback in my Cocoa class. Now there is no way I can pass that callback a userData/refcon pointer to kn

In my app I use the JavaScriptCore API to install a JS function in the WebView context with a C callback in my Cocoa class. Now there is no way I can pass that callback a userData/refcon pointer to know what class the callback belongs to开发者_如何学Go.

Is there a way to resolve this without passing a pointer? Globals don't seem to work since they get overwritten by other class instances.


If a global won't work (because of multiple / concurrent calls, most likely), then you need some kind of context info.

If the API returns any kind of a unique identifier -- session #, an allocated struct, anything -- you could set up an NSMapTable that maps between that identifier and whatever Objective-C goop you might need.

0

精彩评论

暂无评论...
验证码 换一张
取 消