swift – Find out how to make Flutter technique channel look forward to end result earlier than sending it in IOS?

[ad_1]

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

  • On the primary attempt, it sends the end result instantly with a null worth when the display screen is opened.
  • On the second attempt, it sends the token of the primary attempt instantly when the display screen 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) {}
    non-public var eventSink: FlutterEventSink?
        @Printed non-public(set) var initialized = false
        @Printed non-public(set) var token: PianoIDToken?

That is the applying 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 is just not sort FlutterViewController")
    }
    let socialConnectChannel = FlutterMethodChannel(identify: ChannelName.socialConnect,
                                              binaryMessenger: controller.binaryMessenger)
    socialConnectChannel.setMethodCallHandler({
      [weak self] (name: FlutterMethodCall, end result: FlutterResult) -> Void in
      guard name.technique == "getSocialConnect" else {
        end result(FlutterMethodNotImplemented)
        return
      }
        PianoID.shared.endpointUrl = Settings.endpoint.api
        PianoID.shared.support = Settings.support
        PianoID.shared.googleClientId = Settings.googleClientId
        PianoID.shared.delegate = self
            
        PianoOAuth.PianoIDApplicationDelegate.shared.software(software, didFinishLaunchingWithOptions: launchOptions)
        self?.initPianoID(end result: end result)
    })
    return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
  }

That is the callback operate :

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

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

non-public func initPianoID(end result: FlutterResult) {

    PianoID.shared.signIn()

    end result(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) {}
  non-public var eventSink: FlutterEventSink?
    @Printed non-public(set) var initialized = false
    @Printed non-public(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 is just not sort FlutterViewController")
    }
    let socialConnectChannel = FlutterMethodChannel(identify: ChannelName.socialConnect,
                                              binaryMessenger: controller.binaryMessenger)
    socialConnectChannel.setMethodCallHandler({
      [weak self] (name: FlutterMethodCall, end result: FlutterResult) -> Void in
      guard name.technique == "getSocialConnect" else {
        end result(FlutterMethodNotImplemented)
        return
      }
        PianoID.shared.endpointUrl = Settings.endpoint.api
        PianoID.shared.support = Settings.support
        PianoID.shared.googleClientId = Settings.googleClientId
        PianoID.shared.delegate = self
        PianoOAuth.PianoIDApplicationDelegate.shared.software(software, didFinishLaunchingWithOptions: launchOptions)
        self?.initPianoID(end result: end result)
    })
    return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
  }
    /// Signal In callback
        func signIn(end result: PianoIDSignInResult!, withError error: Error!) {
            if let r = end result {
                token = r.token
            } else {
            }
        }
        /// Signal Out callback
        func signOut(withError error: Error!) {
            token = nil
        }
        /// Cancel callback
        func cancel() {
        }
  non-public func initPianoID(end result: FlutterResult) {
    PianoID.shared.signIn()
    end result(self!.token?.accessToken)
  }
}

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *