7#import <AudioToolbox/AudioToolbox.h>
8#import <Foundation/Foundation.h>
9#import <UIKit/UIApplication.h>
10#import <UIKit/UIKit.h>
13#import "flutter/shell/platform/darwin/common/InternalFlutterSwiftCommon/InternalFlutterSwiftCommon.h"
38 "io.flutter.plugin.platform.SystemChromeOrientationNotificationName";
40 "io.flutter.plugin.platform.SystemChromeOrientationNotificationKey";
42 "io.flutter.plugin.platform.SystemChromeOverlayNotificationName";
44 "io.flutter.plugin.platform.SystemChromeOverlayNotificationKey";
52 if (flutterApplication) {
53 flutterApplication.statusBarHidden = hidden;
55 [FlutterLogger logWarning:
@"Application based status bar styling is not available in app "
62 if (flutterApplication) {
65 [flutterApplication setStatusBarStyle:style];
67 [FlutterLogger logWarning:
@"Application based status bar styling is not available in app "
81@property(nonatomic, assign)
BOOL enableViewControllerBasedStatusBarAppearance;
87@property(nonatomic, strong) UITextField* textField;
98 NSObject* infoValue = [[NSBundle mainBundle]
99 objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"];
100#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
101 if (infoValue != nil && ![infoValue isKindOfClass:[NSNumber class]]) {
102 [FlutterLogger logError:@"The value of UIViewControllerBasedStatusBarAppearance in "
103 "Info.plist must be a Boolean type."];
106 _enableViewControllerBasedStatusBarAppearance =
107 (infoValue == nil || [(NSNumber*)infoValue boolValue]);
114 NSString* method = call.
method;
116 if ([method isEqualToString:
@"SystemSound.play"]) {
117 [
self playSystemSound:args];
119 }
else if ([method isEqualToString:
@"HapticFeedback.vibrate"]) {
120 [
self vibrateHapticFeedback:args];
122 }
else if ([method isEqualToString:
@"SystemChrome.setPreferredOrientations"]) {
123 [
self setSystemChromePreferredOrientations:args];
125 }
else if ([method isEqualToString:
@"SystemChrome.setApplicationSwitcherDescription"]) {
126 [
self setSystemChromeApplicationSwitcherDescription:args];
128 }
else if ([method isEqualToString:
@"SystemChrome.setEnabledSystemUIOverlays"]) {
129 [
self setSystemChromeEnabledSystemUIOverlays:args];
131 }
else if ([method isEqualToString:
@"SystemChrome.setEnabledSystemUIMode"]) {
132 [
self setSystemChromeEnabledSystemUIMode:args];
134 }
else if ([method isEqualToString:
@"SystemChrome.restoreSystemUIOverlays"]) {
135 [
self restoreSystemChromeSystemUIOverlays];
137 }
else if ([method isEqualToString:
@"SystemChrome.setSystemUIOverlayStyle"]) {
138 [
self setSystemChromeSystemUIOverlayStyle:args];
140 }
else if ([method isEqualToString:
@"SystemNavigator.pop"]) {
141 NSNumber* isAnimated =
args;
142 [
self popSystemNavigator:isAnimated.boolValue];
144 }
else if ([method isEqualToString:
@"Clipboard.getData"]) {
145 result([
self getClipboardData:
args]);
146 }
else if ([method isEqualToString:
@"Clipboard.setData"]) {
147 [
self setClipboardData:args];
149 }
else if ([method isEqualToString:
@"Clipboard.hasStrings"]) {
150 result([
self clipboardHasStrings]);
151 }
else if ([method isEqualToString:
@"LiveText.isLiveTextInputAvailable"]) {
152 result(@([
self isLiveTextInputAvailable]));
153 }
else if ([method isEqualToString:
@"SearchWeb.invoke"]) {
154 [
self searchWeb:args];
156 }
else if ([method isEqualToString:
@"LookUp.invoke"]) {
157 [
self showLookUpViewController:args];
159 }
else if ([method isEqualToString:
@"Share.invoke"]) {
160 [
self showShareViewController:args];
162 }
else if ([method isEqualToString:
@"ContextMenu.showSystemContextMenu"]) {
163 [
self showSystemContextMenu:args];
165 }
else if ([method isEqualToString:
@"ContextMenu.hideSystemContextMenu"]) {
166 [
self hideSystemContextMenu];
173- (void)showSystemContextMenu:(NSDictionary*)args {
174 if (@available(iOS 16.0, *)) {
177 if (!shownEditMenu) {
178 [FlutterLogger logError:@"Only text input supports system context menu for now. Ensure the "
179 "system context menu is shown with an active text input connection. "
180 "See https://github.com/flutter/flutter/issues/143033."];
185- (void)hideSystemContextMenu {
186 if (@available(iOS 16.0, *)) {
188 [textInputPlugin hideEditMenu];
192- (void)showShareViewController:(NSString*)content {
193 UIViewController* engineViewController = [
self.engine viewController];
195 NSArray* itemsToShare = @[ content ?: [NSNull null] ];
196 UIActivityViewController* activityViewController =
197 [[UIActivityViewController alloc] initWithActivityItems:itemsToShare
198 applicationActivities:nil];
200 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
209 caretRectForPosition:(FlutterTextPosition*)range.start];
211 localRectFromFrameworkTransform:firstRect];
213 caretRectForPosition:(FlutterTextPosition*)range.end];
215 localRectFromFrameworkTransform:lastRect];
217 activityViewController.popoverPresentationController.sourceView = engineViewController.view;
219 activityViewController.popoverPresentationController.sourceRect =
220 CGRectMake(fmin(transformedFirstRect.origin.x, transformedLastRect.origin.x),
221 transformedFirstRect.origin.y,
222 abs(transformedLastRect.origin.x - transformedFirstRect.origin.x),
223 transformedFirstRect.size.height);
226 [engineViewController presentViewController:activityViewController animated:YES completion:nil];
229- (void)searchWeb:(NSString*)searchTerm {
231 if (flutterApplication == nil) {
232 [FlutterLogger logWarning:@"SearchWeb.invoke is not availabe in app extension."];
236 NSString* escapedText = [searchTerm
237 stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
238 URLHostAllowedCharacterSet]];
239 NSString* searchURL = [NSString stringWithFormat:@"%@%@", kSearchURLPrefix, escapedText];
241 [flutterApplication openURL:[NSURL URLWithString:searchURL] options:@{} completionHandler:nil];
244- (void)playSystemSound:(NSString*)soundType {
245 if ([soundType isEqualToString:
@"SystemSoundType.click"]) {
248 AudioServicesPlaySystemSound(kKeyPressClickSoundId);
249 }
else if ([soundType isEqualToString:
@"SystemSoundType.tick"]) {
250 AudioServicesPlaySystemSound(kWheelsOfTimeSoundId);
254- (void)vibrateHapticFeedback:(NSString*)feedbackType {
256 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
260 if ([
@"HapticFeedbackType.lightImpact" isEqualToString:feedbackType]) {
261 [[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight] impactOccurred];
262 }
else if ([
@"HapticFeedbackType.mediumImpact" isEqualToString:feedbackType]) {
263 [[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium] impactOccurred];
264 }
else if ([
@"HapticFeedbackType.heavyImpact" isEqualToString:feedbackType]) {
265 [[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy] impactOccurred];
266 }
else if ([
@"HapticFeedbackType.selectionClick" isEqualToString:feedbackType]) {
267 [[[UISelectionFeedbackGenerator alloc] init] selectionChanged];
271- (void)setSystemChromePreferredOrientations:(NSArray*)orientations {
272 UIInterfaceOrientationMask mask = 0;
274 if (orientations.count == 0) {
275 mask |= UIInterfaceOrientationMaskAll;
277 for (NSString* orientation in orientations) {
278 if ([orientation isEqualToString:
@"DeviceOrientation.portraitUp"]) {
279 mask |= UIInterfaceOrientationMaskPortrait;
280 }
else if ([orientation isEqualToString:
@"DeviceOrientation.portraitDown"]) {
281 mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
282 }
else if ([orientation isEqualToString:
@"DeviceOrientation.landscapeLeft"]) {
283 mask |= UIInterfaceOrientationMaskLandscapeLeft;
284 }
else if ([orientation isEqualToString:
@"DeviceOrientation.landscapeRight"]) {
285 mask |= UIInterfaceOrientationMaskLandscapeRight;
293 [[NSNotificationCenter defaultCenter]
294 postNotificationName:@(kOrientationUpdateNotificationName)
296 userInfo:@{@(kOrientationUpdateNotificationKey) : @(mask)}];
299- (void)setSystemChromeApplicationSwitcherDescription:(NSDictionary*)object {
303- (void)setSystemChromeEnabledSystemUIOverlays:(NSArray*)overlays {
304 BOOL statusBarShouldBeHidden = ![overlays containsObject:@"SystemUiOverlay.top"];
305 if ([overlays containsObject:
@"SystemUiOverlay.bottom"]) {
306 [[NSNotificationCenter defaultCenter]
307 postNotificationName:FlutterViewControllerShowHomeIndicator
310 [[NSNotificationCenter defaultCenter]
311 postNotificationName:FlutterViewControllerHideHomeIndicator
314 if (
self.enableViewControllerBasedStatusBarAppearance) {
315 [
self.engine viewController].prefersStatusBarHidden = statusBarShouldBeHidden;
327- (void)setSystemChromeEnabledSystemUIMode:(NSString*)mode {
328 BOOL edgeToEdge = [mode isEqualToString:@"SystemUiMode.edgeToEdge"];
329 if (
self.enableViewControllerBasedStatusBarAppearance) {
330 [
self.engine viewController].prefersStatusBarHidden = !edgeToEdge;
340 [[NSNotificationCenter defaultCenter]
341 postNotificationName:edgeToEdge ? FlutterViewControllerShowHomeIndicator
342 : FlutterViewControllerHideHomeIndicator
346- (void)restoreSystemChromeSystemUIOverlays {
350- (void)setSystemChromeSystemUIOverlayStyle:(NSDictionary*)message {
351 NSString* brightness =
message[@"statusBarBrightness"];
352 if (brightness == (
id)[NSNull null]) {
356 UIStatusBarStyle statusBarStyle;
357 if ([brightness isEqualToString:
@"Brightness.dark"]) {
358 statusBarStyle = UIStatusBarStyleLightContent;
359 }
else if ([brightness isEqualToString:
@"Brightness.light"]) {
360 statusBarStyle = UIStatusBarStyleDarkContent;
365 if (
self.enableViewControllerBasedStatusBarAppearance) {
367 [[NSNotificationCenter defaultCenter]
368 postNotificationName:@(kOverlayStyleUpdateNotificationName)
370 userInfo:@{@(kOverlayStyleUpdateNotificationKey) : @(statusBarStyle)}];
376- (void)popSystemNavigator:(
BOOL)isAnimated {
384 UINavigationController* navigationController = [engineViewController navigationController];
385 if (navigationController) {
386 [navigationController popViewControllerAnimated:isAnimated];
388 UIViewController* rootViewController = nil;
390 if (flutterApplication) {
391 rootViewController = flutterApplication.keyWindow.rootViewController;
393 if (@available(iOS 15.0, *)) {
395 [engineViewController flutterWindowSceneIfViewLoaded].keyWindow.rootViewController;
397 [FlutterLogger logWarning:@"rootViewController is not available in application extension "
398 "prior to iOS 15.0."];
402 if (engineViewController != rootViewController) {
403 [engineViewController dismissViewControllerAnimated:isAnimated completion:nil];
408- (NSDictionary*)getClipboardData:(NSString*)format {
409 UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
411 NSString* stringInPasteboard = pasteboard.string;
413 return stringInPasteboard == nil ? nil : @{
@"text" : stringInPasteboard};
418- (void)setClipboardData:(NSDictionary*)data {
419 UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
420 id copyText =
data[@"text"];
421 if ([copyText isKindOfClass:[NSString class]]) {
422 pasteboard.string = copyText;
424 pasteboard.string =
@"null";
428- (NSDictionary*)clipboardHasStrings {
429 return @{
@"value" : @([UIPasteboard generalPasteboard].hasStrings)};
432- (
BOOL)isLiveTextInputAvailable {
433 return [[
self textField] canPerformAction:@selector(captureTextFromCamera:) withSender:nil];
436- (void)showLookUpViewController:(NSString*)term {
437 UIViewController* engineViewController = [
self.engine viewController];
438 UIReferenceLibraryViewController* referenceLibraryViewController =
439 [[UIReferenceLibraryViewController alloc] initWithTerm:term];
440 [engineViewController presentViewController:referenceLibraryViewController
445- (UITextField*)textField {
446 if (_textField == nil) {
447 _textField = [[UITextField alloc] init];
void(^ FlutterResult)(id _Nullable result)
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS GBytes * message
#define FML_DCHECK(condition)
UIApplication * application
UIView< UITextInput > * textInputView()
BOOL showEditMenu:(ios(16.0) API_AVAILABLE)
FlutterTextInputPlugin * textInputPlugin
FlutterTextInputPlugin * _textInputPlugin
constexpr char kTextPlainFormat[]
Clipboard plain text format.
const UInt32 kKeyPressClickSoundId
NSString *const kSearchURLPrefix
const UInt32 kWheelsOfTimeSoundId
const char *const kOrientationUpdateNotificationKey
const char *const kOverlayStyleUpdateNotificationName
const char *const kOverlayStyleUpdateNotificationKey
const char *const kOrientationUpdateNotificationName
std::shared_ptr< const fml::Mapping > data