C-callback without class pointer
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.
精彩评论