swift – How you can make Flutter technique channel watch for outcome earlier than sending it in IOS?

[ad_1]

I’m utilizing a sdk piano technique in ios which opens an OAuth display,
the issue is that once I click on on the button flutter technique channel open the display, it’s needed to attend till the display is closed to ship the outcome to the flutter,

  • On the primary attempt, it sends the outcome instantly with a null worth when the display is opened.
  • On the second attempt, it sends the token of the primary attempt instantly when the display is opened.

That is my class and the declaration in AppDelegate :

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, PianoIDDelegate {
    func pianoID(_ pianoID: PianoOAuth.PianoID, didSignInForToken token: PianoOAuth.PianoIDToken!, withError error: Error!) {}
    func pianoID(_ pianoID: PianoOAuth.PianoID, didSignOutWithError error: Error!) {}
    func pianoIDSignInDidCancel(_ pianoID: PianoOAuth.PianoID) {}
    personal var eventSink: FlutterEventSink?
        @Printed personal(set) var initialized = false
        @Printed personal(set) var token: PianoIDToken?

That is the appliance operate with the flutter technique channel :

override func software(
    _ software: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    guard let controller = window?.rootViewController as? FlutterViewController else {
      fatalError("rootViewController will not be sort FlutterViewController")
    }
    let socialConnectChannel = FlutterMethodChannel(identify: ChannelName.socialConnect,
                                              binaryMessenger: controller.binaryMessenger)
    socialConnectChannel.setMethodCallHandler({
      [weak self] (name: FlutterMethodCall, outcome: FlutterResult) -> Void in
      guard name.technique == "getSocialConnect" else {
        outcome(FlutterMethodNotImplemented)
        return
      }
        PianoID.shared.endpointUrl = Settings.endpoint.api
        PianoID.shared.help = Settings.help
        PianoID.shared.googleClientId = Settings.googleClientId
        PianoID.shared.delegate = self
            
        PianoOAuth.PianoIDApplicationDelegate.shared.software(software, didFinishLaunchingWithOptions: launchOptions)
        self?.initPianoID(outcome: outcome)
    })
    return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
  }

That is the callback operate :

// Signal In callback
        func signIn(outcome: PianoIDSignInResult!, withError error: Error!) {
            if let r = outcome {
                token = r.token
            } else {
            }
        }

This the the strategy that I am calling it in flutter technique channel :
This technique will open the authentification display

personal func initPianoID(outcome: FlutterResult) {

    PianoID.shared.signIn()

    outcome(self!.token?.accessToken)
  }

That is all the category :

import UIKit
import Flutter
import PianoOAuth
import PianoComposer
enum ChannelName {
  static let socialConnect = "com.instance.oauth2flutter/socialConnect"
}
enum MyFlutterErrorCode {
  static let unavailable = "UNAVAILABLE"
}
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, PianoIDDelegate {
    func pianoID(_ pianoID: PianoOAuth.PianoID, didSignInForToken token: PianoOAuth.PianoIDToken!, withError error: Error!) {}
    func pianoID(_ pianoID: PianoOAuth.PianoID, didSignOutWithError error: Error!) {}
    func pianoIDSignInDidCancel(_ pianoID: PianoOAuth.PianoID) {}
  personal var eventSink: FlutterEventSink?
    @Printed personal(set) var initialized = false
    @Printed personal(set) var token: PianoIDToken?
  override func software(
    _ software: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    guard let controller = window?.rootViewController as? FlutterViewController else {
      fatalError("rootViewController will not be sort FlutterViewController")
    }
    let socialConnectChannel = FlutterMethodChannel(identify: ChannelName.socialConnect,
                                              binaryMessenger: controller.binaryMessenger)
    socialConnectChannel.setMethodCallHandler({
      [weak self] (name: FlutterMethodCall, outcome: FlutterResult) -> Void in
      guard name.technique == "getSocialConnect" else {
        outcome(FlutterMethodNotImplemented)
        return
      }
        PianoID.shared.endpointUrl = Settings.endpoint.api
        PianoID.shared.help = Settings.help
        PianoID.shared.googleClientId = Settings.googleClientId
        PianoID.shared.delegate = self
        PianoOAuth.PianoIDApplicationDelegate.shared.software(software, didFinishLaunchingWithOptions: launchOptions)
        self?.initPianoID(outcome: outcome)
    })
    return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
  }
    /// Signal In callback
        func signIn(outcome: PianoIDSignInResult!, withError error: Error!) {
            if let r = outcome {
                token = r.token
            } else {
            }
        }
        /// Signal Out callback
        func signOut(withError error: Error!) {
            token = nil
        }
        /// Cancel callback
        func cancel() {
        }
  personal func initPianoID(outcome: FlutterResult) {
    PianoID.shared.signIn()
    outcome(self!.token?.accessToken)
  }
}

[ad_2]

Leave a Reply