-
-
Notifications
You must be signed in to change notification settings - Fork 59
Native properties provided by internal classes are not available #1149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Glad to see this fixed, we're facing the same with |
@lambourn Actually we still haven't fixed the bug in the runtime. You can temporarily switch to the |
@mbektchiev ok, I'll rephrase: "I'll be happy once this is fixed" ;-) We use the Once more, it's great that {N} offers this kind of flexibility to work with the underlying runtime. Otherwise it would be a show stopper. |
Hey guys, just to add more on workarounds - in some cases class NativePropertyReader {
private _invocationCache = new Map<string, NSInvocation>();
private getInvocationObject(object: NSObject, selector: string): NSInvocation {
let invocation = this._invocationCache.get(selector);
if (!invocation) {
const sig = object.methodSignatureForSelector(selector);
invocation = NSInvocation.invocationWithMethodSignature(sig);
invocation.selector = selector;
this._invocationCache[selector] = invocation;
}
return invocation;
}
public readProp<T>(object: NSObject, prop: string, type: interop.Type<T>): T {
const invocation = this.getInvocationObject(object, prop);
invocation.invokeWithTarget(object);
const ret = new interop.Reference<T>(type, new interop.Pointer());
invocation.getReturnValue(ret);
return ret.value;
}
} Then use it to read your property in the following way: const tasksReader = new NativePropertyReader();
const thePropertyValue = tasksReader.readProp(someNativeObject, "thePropertyName", interop.types.int64); We've used the same approach in background-http plugin, so you can use it as reference. Hope this helps. |
Yet another case with similar problems was reported by @triniwiz:
This second scenario hasn't worked even before the regression of the original issue and is related to #1127. I'm working on a solution right now and it should handle both cases. |
Environment
Describe the bug
There are cases in the iOS SDK where the public headers information (which is the source of NativeScript's metadata) and the actual internal classes which comprise the APIs are different. E.g. Let's consider the inconsistencies of downloadTaskWithURL:completionHandler: method of NSURLSession:
__NSCFLocalDownloadTask
(tested on iOS 12.1)NSURLSessionDownloadTask
. Its base class hierarchy is:__NSCFLocalDownloadTask -> __NSCFLocalSessionTask -> __NSCFURLSessionTask -> NSURLSessionTask -> NSObject
NSURLSessionDownloadTask
doesn't implement theresponse
selector=> As a result, the iOS runtime hides this property (along with several others) and reports them as
undefined
.To Reproduce
Execute the following JavaScript:
=> The first
log
correctly prints theresponse
object. While the second one printsundefined
.Expected behavior
Both logs should be identical.
Additional context
The issue has been introduced with the additional filtering implemented with #1086.
Discovered with NativeScript/nativescript-background-http#214
Workaround
As a workaround, such methods, property getters or setters can be invoked dynamically via performSelector, performSelector:withObject: or performSelector:withObject:withObject:
When the return value is not an Objective-C object the above methods will not work correctly. In such cases,
NSInvocation
should be used like it's done here: https://github.com/NativeScript/nativescript-background-http/pull/222/files#diff-4d82b00cf4fca680654c7e489bc635b2R235The text was updated successfully, but these errors were encountered: