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

Two way communication #12

Closed
yackermann opened this issue Jun 16, 2017 · 12 comments
Closed

Two way communication #12

yackermann opened this issue Jun 16, 2017 · 12 comments
Labels

Comments

@yackermann
Copy link
Contributor

How would you implement two way communication described in http://x-callback-url.com/examples/

Something like:

targetapp://x-callback-url/translate?
x-success=sourceapp://x-callback-url/acceptTranslation&
x-source=SourceApp&
x-error=sourceapp://x-callback-url/translationError&
word=Hello&
language=Spanish

@phimage
Copy link
Owner

phimage commented Jun 16, 2017

Using closure on one side to receive response
https://github.com/phimage/CallbackURLKit#use-callback-closure

And on the other side by calling success(with param or not) or failure(with error) or cancel
https://github.com/phimage/CallbackURLKit#add-new-action

@yackermann
Copy link
Contributor Author

@phimage so do I need to declare a new manager instance in my client class to handle incoming callbacks?

@phimage
Copy link
Owner

phimage commented Jun 16, 2017

one manager by app, you can use the default one

@yackermann
Copy link
Contributor Author

yackermann commented Jun 17, 2017

@phimage ok, I don't exactly understand closures with on* operations

I have Client class with a method that does call.

            try self.perform(action: "runOperation", parameters: parameters,  onSuccess: { parameters in
                
            }, onFailure: nil, onCancel: nil)

How do I pass sourceapp://x-callback-url/acceptTranslation on x-success?

@phimage
Copy link
Owner

phimage commented Jun 17, 2017

did you need to know how to do it exactly or just fulfil a need to interact with two of your applications?
Maybe one is not yours and need specific this url

The framework do it automatically but use sourceapp://x-callback-url/response/ for error or success and pass an ID to retrieve the code to execute in callback

And in closure you can execute the code that could be call in an action called "acceptTranslation"

I can add parameters to implement such behaviour if I have time...

@yackermann
Copy link
Contributor Author

@phimage https://github.com/phimage/CallbackURLKit/blob/master/Sources/Manager.swift#L197
that implies that callback will happen to /response?

@phimage
Copy link
Owner

phimage commented Jun 18, 2017

Yes this is the code
This is an auto communication, and success, ..., closure will be called

We could add an 'Action'(string) by callback type and change here the URL if this action is specified

@yackermann
Copy link
Contributor Author

yackermann commented Jun 19, 2017

@phimage hm.. Can't I just set it as one of the params?

let parameters = [
    "x-succes": "sourceapp://x-callback-url/acceptTranslation"
]

@yackermann
Copy link
Contributor Author

@phimage additionally I am adding this plugin to the ObjectiveC app, and app delegate is actually in obj-c, and I can figure out how to add Manager.shared to pass it url handling

@phimage
Copy link
Owner

phimage commented Jun 19, 2017

yes you can try to put this as parameters, never tried... I expect that I do not filter it

for obj-c I never tried if there is some incompatibility
You cannot access register ?

CallbackURLKit.register(action: "acceptTranslation") { parameters, _, _, _ in

}

@yackermann
Copy link
Contributor Author

@phimage Setting as parameter works.

I am working on Objective-c event binding to swift. I found this is how they do it in https://github.com/aerogear/aerogear-cordova-oauth2/

Here they are catching call https://github.com/aerogear/aerogear-cordova-oauth2/blob/master/src/ios/AppDelegate%2Burl.m#L36 which calls notification event

and here is the handler for event https://github.com/aerogear/aerogear-cordova-oauth2/blob/master/src/ios/oauth-0.4.0/OAuth2Module.swift#L92

@phimage
Copy link
Owner

phimage commented Jun 20, 2017

with swizzle they try to achieve this automatically but it's not mandatory
https://github.com/phimage/CallbackURLKit#handle-incoming-urls

@phimage phimage closed this as completed Jul 7, 2017
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