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

Explicit handlers for success and error callbacks #30

Closed
dshomoye opened this issue Mar 6, 2021 · 3 comments
Closed

Explicit handlers for success and error callbacks #30

dshomoye opened this issue Mar 6, 2021 · 3 comments

Comments

@dshomoye
Copy link

dshomoye commented Mar 6, 2021

This is not so much of a problem, but more of a question (not sure where else to ask).
It's my first time writing swift and working with xcode so apologies if this looks trivial:

Here's my set up:
I have added a URL type to my app:

image

I created a custom client for the Bear app:

class BearClient: Client {
    init() {
        super.init(urlScheme: "bear")
    }
    public func search(query: String) {
        let parameters = ["term": query]
        do {
            try self.perform(
                action: "search",
                parameters: parameters,
                onSuccess: { parameters in
                    print(parameters?["notes"])
                },
                onFailure: {error in
                    print(error)
                },
                onCancel: {
                    print("cancelled")
                }
            )
        } catch {
//            NOOP
        }
    }
}

I have the manager initialized:

import SwiftUI
import CallbackURLKit

let manager = Manager.shared

@main
struct LookBackApp: App {
    
    init() {
        manager.callbackURLScheme = "lookback"
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL(perform: { url in
                   _ = manager.handleOpen(url: url)
                })
        }
    }
}

When I call the client like so:

        let client = BearClient()
        client.search(query: "the")

the client runs (and the Bear app opens with the right search query) but the onSuccess callback is never called.

What am I missing? I was assuming I don't create any specific handlers for success and error on the manager because that is not documented.

@dshomoye
Copy link
Author

dshomoye commented Mar 6, 2021

Okay so I just noticed that the callback does seem to be working - but each onSuccess callback is spinning up a separate window. The actual callback that's passed doesn't get triggered, but specifying a callback will make the app receive the results in a new instance that macOs spins up. I'm guessing this is probably because iOS doesn't have to worry about windows. If I could figure out a way to get SwiftUI to always redirect to the current window then I think this could be resolved.

@phimage
Copy link
Owner

phimage commented Mar 17, 2021

the callback are called only if the app respond to it, this an optional part of the protocol

for that an action must be implemented like described
https://github.com/phimage/CallbackURLKit#add-new-action
success, failure, cancel are closure to call to respond

there is an example here
https://github.com/phimage/CallbackURLKit/blob/master/SampleApp/CallbackURLKitDemo/CallbackURLKitDemo.swift#L43

@dshomoye
Copy link
Author

Thanks for replying! I haven't gotten around to testing this but I don't really need the app anymore, for now.
Don't want to keep issues cluttered so I'll close this.

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

No branches or pull requests

2 participants