Skip to content

djmadcat/UIDevice-BlurEnabled

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UIDevice-BlurEnabled

UIDevice category to check whether blur is enabled.

Overview

This is a hack method to check whether blur is enabled on current device. It is based on testing of rendering blur effect at runtime.

How it works

  1. We create UIView with custom backgroundColor
  2. Add UIToolbar with translucent = YES to UIView
  3. Add UIView to UIWindow beyond the screen (this allows you to perform UIView rendering)
  4. Check rendered colors with tricky algorithm
  5. Remove UIView from UIWindow

You must check be_blurEffectEnabled at every applicationDidBecomeActive: call or by subscribing to UIApplicationDidBecomeActiveNotification in your controller or custom view to fix views' rendering settings.

Dependencies

  • 'UIView-JTViewToImage', '~> 0.1' to take screenshot of UIView as UIImage
  • 'OBShapedButton', '~> 1.0.2' to access the pixel color

Example usage

#import "UIDevice+BlurEnabled.h"

@implementation BEViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIDevice *currentDevice = [UIDevice currentDevice];
    NSLog(@"Blur supported by device and OS: %@", [currentDevice be_blurEffectSupported] ? @"YES" : @"NO");
    NSLog(@"Blur active ('increase contrast' disabled): %@", [currentDevice be_blurEffectActive] ? @"YES" : @"NO");
    NSLog(@"Blur enabled (supported && active): %@", [currentDevice be_blurEffectEnabled] ? @"YES" : @"NO");
}

@end

Read more

Contact

Alexey Aleshkov

License

UIDevice-BlurEnabled is available under the BSD 2-Clause license. See the LICENSE file for more info.

About

UIDevice category to check whether blur is enabled.

Resources

License

Stars

Watchers

Forks

Packages