How to detect whether Apple Pencil 2 is connected to an iPad Pro 3rd-gen

iPad Pro 3rd-gen and Apple Pencil2 is coming, I am going to prepare the update for my drawing app. But I am not going to buy the new devices, then the question is, how to modify the Apple Pencil detection code for the new device?

Current code is as below,

if ([central state] == CBManagerStatePoweredOn)
{
    // Device information UUID
    NSArray* myArray = [NSArray arrayWithObject:[CBUUID UUIDWithString:@"180A"]];

    NSArray* peripherals = [m_centralManager retrieveConnectedPeripheralsWithServices:myArray];
    for (CBPeripheral* peripheral in peripherals)
    {
        if ([[peripheral name] containSubstring:@"Apple Pencil"])
        {
            // The Apple pencil is connected
            self.stylusType = Stylus_ApplePencil;
            [self.delegate didConnectStylus:Stylus_ApplePencil];
        }
    }
}


The uuid of Apple Pencil 1st-gen is "180A", what's is the new uuid and peripheral name then?

Replies

Curious why you're doing a device (UUID/name string) check at all, say, versus a (azimuth and altitude) property check that would indicate an apple pencil proper.


It's better to avoid UUID and decouple your app from hard coded references so that you don't have to update each time a new pencil comes along.