From a6f0be9844546672bdeaaff9ad02c240c840dc9e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 13 Feb 2018 11:49:43 -0800 Subject: [PATCH] Fix unguarded availability warnings for iOS (flutter/engine#4664) Place all iOS code that relies on APIs introduced in iOS versions later than our base SDK version (iOS 8) behind @available checks. This allows us to enable the -Wunguarded-availability compiler flag for iOS builds in the buildroot repo. --- .../framework/Source/FlutterAppDelegate.mm | 2 +- .../framework/Source/FlutterViewController.mm | 34 +++++++------------ .../platform/darwin/ios/ios_gl_context.mm | 3 +- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 63000fede1..5f7f440be4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -198,7 +198,7 @@ - (void)application:(UIApplication*)application performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem - completionHandler:(void (^)(BOOL succeeded))completionHandler { + completionHandler:(void (^)(BOOL succeeded))completionHandler NS_AVAILABLE_IOS(9_0) { for (id plugin in _pluginDelegates) { if ([plugin respondsToSelector:_cmd]) { if ([plugin application:application diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 461696896a..44ee89abf9 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -78,9 +78,6 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { fml::scoped_nsprotocol _settingsChannel; fml::scoped_nsprotocol _launchView; int64_t _nextTextureId; - bool _platformSupportsTouchTypes; - bool _platformSupportsTouchPressure; - bool _platformSupportsTouchOrientationAndTilt; BOOL _initialized; BOOL _connected; } @@ -126,10 +123,6 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse { _initialized = YES; - _platformSupportsTouchTypes = fml::IsPlatformVersionAtLeast(9); - _platformSupportsTouchPressure = fml::IsPlatformVersionAtLeast(9); - _platformSupportsTouchOrientationAndTilt = fml::IsPlatformVersionAtLeast(9, 1); - _orientationPreferences = UIInterfaceOrientationMaskAll; _statusBarStyle = UIStatusBarStyleDefault; _platformView = std::make_shared( @@ -438,20 +431,19 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(UITouc return PointerChangeMapperPhase(blink::PointerData::Change::kCancel, MapperPhase::Accessed); } -static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch, - bool touchTypeSupported) { - if (!touchTypeSupported) { +static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) { + if (@available(iOS 9, *)) { + switch (touch.type) { + case UITouchTypeDirect: + case UITouchTypeIndirect: + return blink::PointerData::DeviceKind::kTouch; + case UITouchTypeStylus: + return blink::PointerData::DeviceKind::kStylus; + } + } else { return blink::PointerData::DeviceKind::kTouch; } - switch (touch.type) { - case UITouchTypeDirect: - case UITouchTypeIndirect: - return blink::PointerData::DeviceKind::kTouch; - case UITouchTypeStylus: - return blink::PointerData::DeviceKind::kStylus; - } - return blink::PointerData::DeviceKind::kTouch; } @@ -492,7 +484,7 @@ static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* to pointer_data.change = eventTypePhase.first; - pointer_data.kind = DeviceKindFromTouchType(touch, _platformSupportsTouchTypes); + pointer_data.kind = DeviceKindFromTouchType(touch); pointer_data.device = device_id; @@ -500,7 +492,7 @@ static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* to pointer_data.physical_y = windowCoordinates.y * scale; // pressure_min is always 0.0 - if (_platformSupportsTouchPressure) { + if (@available(iOS 9, *)) { // These properties were introduced in iOS 9.0. pointer_data.pressure = touch.force; pointer_data.pressure_max = touch.maximumPossibleForce; @@ -515,7 +507,7 @@ static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* to pointer_data.radius_max = touch.majorRadius + touch.majorRadiusTolerance; // These properties were introduced in iOS 9.1 - if (_platformSupportsTouchOrientationAndTilt) { + if (@available(iOS 9.1, *)) { // iOS Documentation: altitudeAngle // A value of 0 radians indicates that the stylus is parallel to the surface. The value of // this property is Pi/2 when the stylus is perpendicular to the surface. diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_gl_context.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_gl_context.mm index 1e4dde9a2f..7a51dbb6b8 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_gl_context.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_gl_context.mm @@ -106,9 +106,8 @@ IOSGLContext::IOSGLContext(PlatformView::SurfaceConfig config, CAEAGLLayer* laye // should use iOS APIs to perform the final correction step based on the // device properties. Ex: We can indicate that we have rendered in P3, and // the framework will do the final adjustment for us. - NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; color_space_ = SkColorSpace::MakeSRGB(); - if (version.majorVersion >= 10) { + if (@available(iOS 10, *)) { UIDisplayGamut displayGamut = [UIScreen mainScreen].traitCollection.displayGamut; switch (displayGamut) { case UIDisplayGamutP3: