Wednesday, September 6, 2023
HomeiOS Developmentios - Flutter occasion channel: easy methods to detect apple pencil double...

ios – Flutter occasion channel: easy methods to detect apple pencil double faucet occasion in flutter


I am new in flutter.
I am now growing a drawing app in flutter, which makes use of apple pencil.

I would like consumer can change to eraser mode once they double-tap the apple pencil.
I’ve already developed particular drawing options, so I don’t wish to use plug-in resembling pencil equipment.
Slightly, I wish to use occasion channel to straight talk with IOS, however I am not aware of the characteristic.

I imagine it’s not working as a result of the pencil interplay is a view interplay however I do not need view?

@ ios/Runner/AppDelegate.swift:

<i>
import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func utility(
    _ utility: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
  
 
    if #out there(iOS 12.1, *) {
      GeneratedPluginRegistrant.register(with: self)
      FlutterEventChannel(identify: "applePencilSideTouch", binaryMessenger: (window?.rootViewController as! FlutterViewController).binaryMessenger).setStreamHandler(PencilStreamHandler())

      }


    return tremendous.utility(utility, didFinishLaunchingWithOptions: launchOptions)
  }
}




@out there(iOS 12.1, *)
 class PencilStreamHandler:FlutterViewController , FlutterStreamHandler, UIPencilInteractionDelegate {
     
     
     override func viewDidLoad() {
       tremendous.viewDidLoad()
         let pencilInteraction = UIPencilInteraction()
         pencilInteraction.delegate = self
         view.addInteraction(pencilInteraction)

     }
     
    var occasions : FlutterEventSink?
    func onListen(withArguments arguments: Any?, eventSink occasions: @escaping FlutterEventSink) -> FlutterError? {
        self.occasions = occasions    
        let pencilInteraction = UIPencilInteraction()
        pencilInteraction.delegate = self
        view.addInteraction(pencilInteraction)
        print("interactionAdded")
      
        NotificationCenter.default.addObserver(self, selector: #selector(self.pencilDidDoubleTap),identify: Notification.Identify("PencilInteractionEvent"),object: nil)
        return nil
    }
    
    func onCancel(withArguments arguments: Any?) -> FlutterError? {
        self.occasions = nil
        return nil
    }
    
 func pencilInteractionDidTap(_ interplay: UIPencilInteraction) {
    NotificationCenter.default.submit(identify: Notification.Identify("PencilInteractionEvent"), object: true)
}
}
</i>

in flutter,

  closing EventChannel _stateChannel = const EventChannel("applePencilSideTouch");
 void initState() {
    tremendous.initState();
    _stateChannel.receiveBroadcastStream().pay attention((occasion) {
       // apple pencil facet double faucet receiver (toggle eraser mode)
    });
</i>



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments