Skip to content
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

x/mobile: ObjC: binding callback #25847

Closed
ensoreus opened this issue Jun 12, 2018 · 3 comments
Closed

x/mobile: ObjC: binding callback #25847

ensoreus opened this issue Jun 12, 2018 · 3 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@ensoreus
Copy link

ensoreus commented Jun 12, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10.1 darwin/amd64

Does this issue reproduce with the latest release?

not sure

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/fil/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/fil/go"
GORACE=""
GOROOT="/opt/local/lib/go"
GOTMPDIR=""
GOTOOLDIR="/opt/local/lib/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="/usr/bin/clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_t/3lgmn1p93kng76718p0hkqh80000gn/T/go-build992461229=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have a Go interface
type GetResponse interface { OnResult(json string) }

I have to subscribe on that event OnResult from ObjC using this interface.
func Subscribe( response GetResponse){ response.OnResult("some json") }

ObjC bind gives me a corresponding protocol and a basic class
`
@interface GetResponse : NSObject <goSeqRefInterface, GetResponse> {
}
@Property(strong, readonly) id _ref;

(instancetype)initWithRef:(id)ref;
(void)onResult:(NSString*)json;
@EnD
`
So, I need to get this json in my ObjC env. How can I do that?

Subclassing If I subclass this GetResponse or just use it as is and pass to Subscribe routine, it crashes
'go_seq_go_to_refnum on objective-c objects is not permitted'
Category if I create struct on Go side with the protocol support, I can't subclass it but at least it's not crashes:
type GetResponseStruct struct{} func (GetResponseStruct) OnResult(json string){log.Info("GO RESULT")} func CreateGetResponse() *GetResponseStruct{ return &GetResponseStruct{} }
I have a solid object without obvious way to hook up my callback. If I make a category and override the onResult routine, it's not called. Just because overriding existing methods of class is not determined behavior according to AppleDoc. Anytime OnResult called from Go, the default implementation invokes and "GO RESULT" appears.
Swizzling I tried to use category and swizzle (replace method's implementation with mine renamed method) but it only works if I call onResult from ObjC env.

What did you expect to see?

I expect to see the #1 way working (with subclassing), with no crash.

What did you see instead?

it crashes
'go_seq_go_to_refnum on objective-c objects is not permitted'

@bcmills
Copy link
Contributor

bcmills commented Jun 12, 2018

I can't parse this report. Is this a problem you encountered when using the gomobile tool? Is this a bug report, or a general question?

If this is a bug report, please include a link to a complete program and the commands used to build it, if possible. (Also see https://guides.github.com/features/mastering-markdown/ for examples of how to format code in GitHub issues.)

We generally prefer golang-nuts for questions, or see https://golang.org/wiki/Questions for other venues.

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. mobile Android, iOS, and x/mobile labels Jun 12, 2018
@bcmills bcmills added this to the Unreleased milestone Jun 12, 2018
@ensoreus
Copy link
Author

ensoreus commented Jun 12, 2018

yes, it's gomobile
I think it's a bug if you have no answer on that presumably "general question".
Commited the "question" on StackOverflow with "go" tag.

@FiloSottile FiloSottile changed the title ObjC: binding callback x/mobile: ObjC: binding callback Jul 19, 2018
@mvdan
Copy link
Member

mvdan commented Jun 15, 2021

Closing old issues that still have the WaitingForInfo label where enough details to investigate weren't provided. Feel free to leave a comment with more details and we can reopen.

@mvdan mvdan closed this as completed Jun 15, 2021
@golang golang locked and limited conversation to collaborators Jun 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants