How to detect if is the old Apple TV Siri Remote (1st generation) or the new Apple TV remote (2nd gen and 3rd gen)

340 Views Asked by At

The market has many users that are using Apple TV remote controller 1st Generation and the new remote with D-Pad clickable.

enter image description here Identify your Apple TV remote

How to distinguish between the two remote controllers? If it is the new command, I want to deactivate the touch area and only use D-Pad which is better for classic games, but to do that I need to find out which version it is. Does anyone know how to do this?

Asking for the vendor and I just get "Remote".

print(microGamepad.controller?.vendorName)
print(microGamepad.device?.vendorName)
//Optional("Remote")
//Optional("Remote")
1

There are 1 best solutions below

2
Kevin Bradley On

GCController has a property called microGamepad Each gamepad is broken up into core elements the element count on the v1 Siri remote is exactly 10, and I know the v2 remote has a higher element count, last I checked it was 18. We can use this tidbit of information to determine whether or not the Siri remote in question is v2+

I add an extension to GCController to determine this information.

Swift:


extension GCController {
    
    class func siriRemote() -> GCController? { //there can be only one Siri Remote paired at a time, so returning a single item is fine
        if kCFCoreFoundationVersionNumber < 1665.15 {
            let gcc = GCController.controllers().filter { controller in
                controller.vendorName == "Remote"
            }
            return gcc.last
        }
        let gcc = GCController.controllers().filter { controller in
            return controller.productCategory.localizedStandardContains("Siri Remote")
        }
        return gcc.last
    }
    
    class func hasV2SiriRemote() -> Bool {
        if let sr = self.siriRemote() {
            return sr.isV2SiriRemote()
        }
        return false
    }
    
    func isV2SiriRemote() -> Bool {
        if kCFCoreFoundationVersionNumber < 1775.118 { //anything under 14.5 cant even pair the V2 siri remote
            return false
        }
        if self.productCategory.localizedStandardContains("Siri Remote") {
            let microGP = self.microGamepad
            if let elementCount = microGP?.elements.count { //Note: 'elements' for GCMicroGamepad is tvOS 14+ only.
                return elementCount > 10
            }
        }
        return false
    }
}

ObjC:


#import <GameController/GameController.h>

@interface GCController (siri)

+(GCController *)siriRemote;
-(BOOL)isV2SiriRemote;
+(BOOL)hasV2SiriRemote;

@end

@implementation GCController (siri)

+(GCController *)siriRemote {
    if (kCFCoreFoundationVersionNumber < 1665.15) {
        return [[[GCController controllers] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"vendorName == %@", @"Remote"]] lastObject];
    }
    return [[[GCController controllers] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"productCategory LIKE %@", @"Siri Remote"]] lastObject];
}

- (BOOL)isV2SiriRemote {
    if (kCFCoreFoundationVersionNumber < 1775.118) { //anything under 14.5 cant even pair the V2 siri remote
        return false;
    }
    if ([[self productCategory] containsString:@"Siri Remote"]){
        GCMicroGamepad *microGP = [self microGamepad];
        if ([microGP respondsToSelector:@selector(elements)]){
            if ([microGP elements].count > 10) {
                return true;
            }
        }
    }
    return false;
}

+(BOOL)hasV2SiriRemote {
    return [[self siriRemote] isV2SiriRemote];
}

@end