Search code examples
iosswiftuiblureffect

Check if device supports blur


My app uses UIBlurEffect, however older devices (specifically iPads 2 and 3, that support iOS 8) don't have blur support.

I'd like to check if the user's device has blur support or not. How do I do it?


Solution

  • UIDevice has an internal method [UIDevice _graphicsQuality] that seems promising, but of course your app will be rejected by Apple. Let's create our own method:

    First of all, we need to know the exact device type we're working on:

    #import <sys/utsname.h>
    
    NSString* deviceName()
    {
        struct utsname systemInfo;
        uname(&systemInfo);
    
        return [NSString stringWithCString:systemInfo.machine
                                  encoding:NSUTF8StringEncoding];
    }
    

    This should return iPad2,1 for iPad 2, for example. Here's an updated list of iDevice models: https://theiphonewiki.com/wiki/Models

    So, let's classify our device models in two groups: those that have poor graphics quality (and thus don't support blur), and those with great graphics quality. According to my investigation, these are the devices that Apple considers with "poor" graphics (these may change in the future):

    iPad iPad1,1 iPhone1,1 iPhone1,2 iPhone2,1 iPhone3,1 iPhone3,2 iPhone3,3 iPod1,1 iPod2,1 iPod2,2 iPod3,1 iPod4,1 iPad2,1 iPad2,2 iPad2,3 iPad2,4 iPad3,1 iPad3,2 iPad3,3

    So we write the following code:

    NSSet *graphicsQuality = [NSSet setWithObjects:@"iPad",
                                                         @"iPad1,1",
                                                         @"iPhone1,1",
                                                         @"iPhone1,2",
                                                         @"iPhone2,1",
                                                         @"iPhone3,1",
                                                         @"iPhone3,2",
                                                         @"iPhone3,3",
                                                         @"iPod1,1",
                                                         @"iPod2,1",
                                                         @"iPod2,2",
                                                         @"iPod3,1",
                                                         @"iPod4,1",
                                                         @"iPad2,1",
                                                         @"iPad2,2",
                                                         @"iPad2,3",
                                                         @"iPad2,4",
                                                         @"iPad3,1",
                                                         @"iPad3,2",
                                                         @"iPad3,3",
                                                         nil];
     if ([graphicsQuality containsObject:deviceName()]) {
         // Device with poor graphics, blur not supported
     } else {
         // Blur supported
     }
    

    Be careful because even though the device may support blur, the user may have disabled advanced visual effects from Settings, Accessibility.

    Alternative method

    https://gist.github.com/conradev/8655650