1111
1212#import " KeyCodeMap_Internal.h"
1313#import " flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"
14+ #import " flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
15+
16+ FLUTTER_ASSERT_ARC
1417
1518namespace {
1619
@@ -165,7 +168,7 @@ static uint64_t GetLogicalKeyForEvent(FlutterUIPressProxy* press, NSNumber* mayb
165168 const char * characters =
166169 getEventCharacters (press.key .charactersIgnoringModifiers , press.key .keyCode );
167170 NSString * keyLabel =
168- characters == nullptr ? nil : [[[ NSString alloc ] initWithUTF8String: characters] autorelease ];
171+ characters == nullptr ? nil : [[NSString alloc ] initWithUTF8String: characters];
169172 NSUInteger keyLabelLength = [keyLabel length ];
170173 // If this key is printable, generate the logical key from its Unicode
171174 // value. Control keys such as ESC, CTRL, and SHIFT are not printable. HOME,
@@ -252,7 +255,7 @@ static bool isKeyDown(FlutterUIPressProxy* press) API_AVAILABLE(ios(13.4)) {
252255 */
253256@interface FlutterKeyPendingResponse : NSObject
254257
255- @property (readonly ) FlutterEmbedderKeyResponder* responder;
258+ @property (readonly , weak ) FlutterEmbedderKeyResponder* responder;
256259
257260@property (nonatomic ) uint64_t responseId;
258261
@@ -302,7 +305,7 @@ - (void)resolveTo:(BOOL)handled;
302305 * Only set in debug mode. Nil in release mode, or if the callback has not been
303306 * handled.
304307 */
305- @property (readonly ) NSString * debugHandleSource;
308+ @property (readonly , copy ) NSString * debugHandleSource;
306309@end
307310
308311@implementation FlutterKeyCallbackGuard {
@@ -319,11 +322,6 @@ - (nonnull instancetype)initWithCallback:(FlutterAsyncKeyCallback)callback {
319322 return self;
320323}
321324
322- - (void )dealloc {
323- [_callback release ];
324- [super dealloc ];
325- }
326-
327325- (void )pendTo : (nonnull NSMutableDictionary <NSNumber*, FlutterAsyncKeyCallback>*)pendingResponses
328326 withId : (uint64_t )responseId {
329327 NSAssert (!_handled, @" This callback has been handled by %@ ." , _debugHandleSource);
@@ -364,7 +362,7 @@ @interface FlutterEmbedderKeyResponder ()
364362 * The keys of the dictionary are physical keys, while the values are the logical keys
365363 * of the key down event.
366364 */
367- @property (nonatomic , retain , readonly ) NSMutableDictionary <NSNumber*, NSNumber*>* pressingRecords;
365+ @property (nonatomic , copy , readonly ) NSMutableDictionary <NSNumber*, NSNumber*>* pressingRecords;
368366
369367/* *
370368 * A constant mask for NSEvent.modifierFlags that Flutter synchronizes with.
@@ -403,7 +401,7 @@ @interface FlutterEmbedderKeyResponder ()
403401 * Its values are |responseId|s, and keys are the callback that was received
404402 * along with the event.
405403 */
406- @property (nonatomic , retain , readonly )
404+ @property (nonatomic , copy , readonly )
407405 NSMutableDictionary <NSNumber*, FlutterAsyncKeyCallback>* pendingResponses;
408406
409407/* *
@@ -502,13 +500,6 @@ - (nonnull instancetype)initWithSendEvent:(FlutterSendKeyEvent)sendEvent {
502500 return self;
503501}
504502
505- - (void )dealloc {
506- [_sendEvent release ];
507- [_pressingRecords release ];
508- [_pendingResponses release ];
509- [super dealloc ];
510- }
511-
512503- (void )handlePress : (nonnull FlutterUIPressProxy*)press
513504 callback : (FlutterAsyncKeyCallback)callback API_AVAILABLE(ios(13.4 )) {
514505 if (@available (iOS 13.4 , *)) {
@@ -522,11 +513,11 @@ - (void)handlePress:(nonnull FlutterUIPressProxy*)press
522513 FlutterKeyCallbackGuard* guardedCallback = nil ;
523514 switch (press.phase ) {
524515 case UIPressPhaseBegan:
525- guardedCallback = [[[ FlutterKeyCallbackGuard alloc ] initWithCallback: callback] autorelease ];
516+ guardedCallback = [[FlutterKeyCallbackGuard alloc ] initWithCallback: callback];
526517 [self handlePressBegin: press callback: guardedCallback];
527518 break ;
528519 case UIPressPhaseEnded:
529- guardedCallback = [[[ FlutterKeyCallbackGuard alloc ] initWithCallback: callback] autorelease ];
520+ guardedCallback = [[FlutterKeyCallbackGuard alloc ] initWithCallback: callback];
530521 [self handlePressEnd: press callback: guardedCallback];
531522 break ;
532523 case UIPressPhaseChanged:
@@ -632,9 +623,9 @@ - (void)sendPrimaryFlutterEvent:(const FlutterKeyEvent&)event
632623 _responseId += 1 ;
633624 uint64_t responseId = _responseId;
634625 FlutterKeyPendingResponse* pending =
635- [[[ FlutterKeyPendingResponse alloc ] initWithHandler: self responseId: responseId] autorelease ];
626+ [[FlutterKeyPendingResponse alloc ] initWithHandler: self responseId: responseId];
636627 [callback pendTo: _pendingResponses withId: responseId];
637- _sendEvent (event, HandleResponse, pending);
628+ _sendEvent (event, HandleResponse, (__bridge_retained void * _Nullable) pending);
638629}
639630
640631- (void )sendEmptyEvent {
@@ -883,7 +874,7 @@ - (UInt32)adjustModifiers:(nonnull FlutterUIPressProxy*)press API_AVAILABLE(ios(
883874
884875namespace {
885876void HandleResponse (bool handled, void * user_data) {
886- FlutterKeyPendingResponse* pending = reinterpret_cast < FlutterKeyPendingResponse*>(user_data) ;
877+ FlutterKeyPendingResponse* pending = (__bridge_transfer FlutterKeyPendingResponse*)user_data ;
887878 [pending.responder handleResponse: handled forId: pending.responseId];
888879}
889880} // namespace
0 commit comments