3

I was wondering if it is possible to simulate the Apple pencil in the iOS simulator.

According to an Apple emloyee here Xcode iOS Simulator: can I use the mouse as pretend Apple Pencil input (on iPad Pro), for testing? it is not possible. And the answer was given in June 2017.

According to https://developer.xamarin.com/guides/cross-platform/windows/ios-simulator/ (very last paragraph: Stylus support in Windows is also translated to Apple Pencil input on the simulator.), using the remote iOS simulator from Xamarin, it is possible to simulate the pencil. (and they have had this feature for some months already)

So, I am a bit confused. As far as I know, Xamarin uses the normal iOS simulator, too. (They just show it via a remote connection on a Windows PC) If they have pencil support in the simulator, it must be possible for anybody, mustn't it?

eikuh
  • 673
  • 1
  • 9
  • 18
  • 1
    You can use the UI Automation framework (via the Instruments interface) to synthesize things like a UITouch while adding Pencil coalesced touches, etc... the issue of course is there is no touch screen/stylus Macs to collect the needed data from... I've seen a Wacom pad that was interfaced to a custom Appium IOS driver that allowed Pencil support for the iOS sim (this was mainly being used to collect Pencil data for Appium UI testing) but could be used as a poor-mans iPad Pro/Pencil combo. – SushiHangover Aug 02 '17 at 05:55
  • Interesting! Thank you! I will take a look at UI Automation framework. – eikuh Aug 04 '17 at 10:46

1 Answers1

2

For those who stuck with this in 2021 try the following:

iOS 14

#if targetEnvironment(simulator)
canvasView.drawingPolicy = .anyInput
#else
canvasView.drawingPolicy = .pencilOnly
#endif

Also in the Settings app there is a global setting called "Only Draw with Apple Pencil". This can be read from UIPencilInteraction.prefersPencilOnlyDrawing in PencilKit.

iOS 13 (only)

#if targetEnvironment(simulator)
canvasView.allowsFingerDrawing = true
#else
canvasView.allowsFingerDrawing = false
#endif

Courtesy of https://stackoverflow.com/a/62567169/2667933

Artem Kirillov
  • 1,132
  • 10
  • 25