Xcode


A Mac developer raised questions about Xcode and Cocoa interface.

If you have a similar query some of the email exchange below may help...

Developer
Do you have a sample Xcode sample app that shows how to setup and use the UPDD driver API within a Mac OS app? 

Response
All you should have to do to make an app that uses the UPDD API is to add the following path to your project's "header search path" setting:

/Library/Application Support/UPDD/api/

And then add the following file to the "Link Binary With Libraries" section of your project's Build Phases:
/usr/local/lib/libupddapi.1.dylib

Then you should be able to include upddapi.h and your project should link successfully.

Developer
Was able to compile the app with the UPDD API. I was missing the link to /usr/local/lib/libupddapi.1.dylib part.

Before I go further, I was wondering do I need to use this API or does the driver already send the right touch events to the standard Cocoa API?

I was expecting to receive callbacks on these functions without having to use the UPDD API:

- (void)magnifyWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)rotateWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)swipeWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)beginGestureWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)endGestureWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);

- (void)smartMagnifyWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_8);
- (void)touchesBeganWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_6);
- (void)touchesMovedWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_6);
- (void)touchesEndedWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_6);
- (void)touchesCancelledWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_6);

Response
Unfortunately it's not possible for all touch-related events to be passed into Cocoa apps. This is partly because MacOS does not have a way of representing touch events with an absolute position and that originate from a touch screen. Rather all touch events are assumed to come from a trackpad.

However, when UPDD Gestures is running, you should be able to receive multi-touch gesture events in your Cocoa app with these callbacks:

- (void)magnifyWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)rotateWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)swipeWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)beginGestureWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)endGestureWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_5);
- (void)smartMagnifyWithEvent:(NSEvent *)event NS_AVAILABLE_MAC(10_8);

Whereas the touches*WithEvent functions will not be used. If you need individual touch positions, that's when it's necessary to use the UPDD API and register a callback function with TBApiRegisterEvent.

Just in case you don't already have it, we make the source code to our UPDD Test application available here.
which demonstrates how to use the UPDD API for receiving both touch and gesture events.

Developer
I have the UPDD Gestures app running, but I never receive the magnify, swipe, etc. events. Maybe I need to enable some options in the Gestures app? 

Response
Do you have an Apple trackpad on hand? If so, can you check and see if your app can receive magnify and rotate events from it?

Developer
I just tried with the trackpad. Magnify and rotate events are received. But not the "Swipe" event -- one finger, two fingers, no luck... even though that's the gesture I'm interested in. That makes me realize I never tried the other gestures with the touch screen. So it's possible they actually work.

While I was testing on the touch screen, I did see in the UPDD Gesture console that swipe Left/Right are being detected when I was swiping with one finger.

Response
In order for UPDD Gestures to create system-wide swipe events, you'll need to set the various swipe gestures to the "Navigate between pages" action. This action is available if you uncheck the "Use XYZ Finger Swipes instead of XYZ Finger Drag" check boxes.

Please note though that if you are unable to get the gestures you want through the macOS API, you can also use the UPDD API to retrieve gesture events from the UPDD itself.

Developer
Just tested with the touch screen and the standard Cocoa events are mapped. The thing I wasn't able to get to work was the Swipe event using one single finger (with 2 fingers, I do get it). But for a user who would be playing around on the touch screen, a two-finger swipe is not the most intuitive.

So what I did was to use NSPanGestureRecognizer and detect a swipe by using some thresholds. Is there something else would you recommend for the one-finger swipe?

Response
Yes, MacOS doesn't actually have a gesture for one finger swipes, at least not that I'm aware of.

If you'd prefer not to use the UPDD API, then maybe try setting single finger drags to the "scroll" action in UPDD Gestures, and then read in the movement by either listening for scroll wheel events, or by using the newer swipe tracking API, i.e. these two methods:

wantsScrollEventsForSwipeTrackingOnAxis:
https://developer.apple.com/documentation/appkit/nsresponder/1527456-wantsscrolleventsforswipetrackin

trackSwipeEventWithOptions:dampenAmountThresholdMin:max:usingHandler:
https://developer.apple.com/documentation/appkit/nsevent/1533300-trackswipeeventwithoptions

Or, maybe you could set single finger drags to a "click and drag" action and just listen for mouse events?

Posted 6 Years Ago, Updated 6 Years Ago
http://support.touch-base.com/Documentation/50513/Xcode