Skip to content

[Feature Request] Expose members of Objective-C internal interfaces #1127

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

Closed
mbektchiev opened this issue Apr 15, 2019 · 0 comments
Closed
Assignees
Labels
Milestone

Comments

@mbektchiev
Copy link
Contributor

mbektchiev commented Apr 15, 2019

Description
When integrating the Spotify SDK into {N}, there were fields which were inaccessible from JavaScript. E.g.
@property (nullable, nonatomic, strong, readonly) id<SPTAppRemotePlayerAPI> playerAPI; turned out to be returning a variable from an internal class which had no metadata in {N}. As a result

console.log('appRemote.playerAPI.subscribeToPlayerState:', appRemote.playerAPI.subscribeToPlayerState);

prints undefined. While

console.log('appRemote.playerAPI:', appRemote.playerAPI);

prints appRemote.playerAPI: <SPTAppRemotePlayerAPIImplemenation: 0x28062a840>

Describe the solution you'd like
It would be convenient if such internal classes' members coming from protocols (with generated metadata) could be accessible from JS out of the box, regardless of the fact that there's no metadata for the classes themselves.

Describe alternatives you've considered
As a workaround with the current state of the runtime, it's possible to manually write code which will generate metadata for the types. One drawback of this approach is that it hardcodes the name of the internal class which might change with newer releases of the same library. In the above case, if one adds:

@interface SPTAppRemotePlayerAPIImplemenation : NSObject<SPTAppRemotePlayerAPI>
@end

in nativescript-spotify/platforms/ios/SpotifyiOS.framework/Headers/SPTAppRemotePlayerAPI.h after the declaration of the SPTAppRemotePlayerAPI protocol or (even better) in a new header included in the umbrella header of the plugin, this code:

console.log('appRemote.playerAPI.subscribeToPlayerState:', appRemote.playerAPI.subscribeToPlayerState);
console.log('appRemote.playerAPI.seekToPosition:', appRemote.playerAPI.seekToPositionCallback);

will correctly output:

CONSOLE LOG file:///app/bundle.js:10168:28: appRemote.playerAPI.subscribeToPlayerState: function subscribeToPlayerState() {
[native code]
}
CONSOLE LOG file:///app/bundle.js:10169:28: appRemote.playerAPI.seekToPosition: function seekToPositionCallback() {
[native code]
}

Additional context
Another workaround that doesn't hardcode the class name is to use dynamic invocation, but it would be even more inconvenient to write and support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants