@@ -40,10 +40,12 @@ - (instancetype)initWithEnableVMServicePublication:(BOOL)enableVMServicePublicat
4040#include < net/if.h>
4141
4242#include " flutter/fml/logging.h"
43- #include " flutter/fml/memory/weak_ptr.h"
4443#include " flutter/fml/message_loop.h"
4544#include " flutter/fml/platform/darwin/scoped_nsobject.h"
4645#include " flutter/runtime/dart_service_isolate.h"
46+ #import " flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
47+
48+ FLUTTER_ASSERT_ARC
4749
4850@protocol FlutterDartVMServicePublisherDelegate
4951- (void )publishServiceProtocolPort : (NSURL *)uri ;
@@ -54,7 +56,7 @@ @interface FlutterDartVMServicePublisher ()
5456+ (NSData *)createTxtData : (NSURL *)url ;
5557
5658@property (readonly , class ) NSString * serviceName;
57- @property (readonly ) fml::scoped_nsobject< NSObject <FlutterDartVMServicePublisherDelegate>> delegate;
59+ @property (readonly ) NSObject <FlutterDartVMServicePublisherDelegate>* delegate;
5860@property (nonatomic , readwrite ) NSURL * url;
5961@property (readonly ) BOOL enableVMServicePublication;
6062
@@ -139,32 +141,31 @@ static void DNSSD_API RegistrationCallback(DNSServiceRef sdRef,
139141
140142@implementation FlutterDartVMServicePublisher {
141143 flutter::DartServiceIsolate::CallbackHandle _callbackHandle;
142- std::unique_ptr<fml::WeakPtrFactory<FlutterDartVMServicePublisher>> _weakFactory;
143144}
144145
145146- (instancetype )initWithEnableVMServicePublication : (BOOL )enableVMServicePublication {
146147 self = [super init ];
147148 NSAssert (self, @" Super must not return null on init." );
148149
149- _delegate. reset ( [[DartVMServiceDNSServiceDelegate alloc ] init ]) ;
150+ _delegate = [[DartVMServiceDNSServiceDelegate alloc ] init ];
150151 _enableVMServicePublication = enableVMServicePublication;
151- _weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterDartVMServicePublisher>> (self);
152+ __weak __typeof (self) weakSelf = self ;
152153
153154 fml::MessageLoop::EnsureInitializedForCurrentThread ();
154155
155156 _callbackHandle = flutter::DartServiceIsolate::AddServerStatusCallback (
156- [weak = _weakFactory->GetWeakPtr (),
157- runner = fml::MessageLoop::GetCurrent ().GetTaskRunner ()](const std::string& uri) {
157+ [weakSelf, runner = fml::MessageLoop::GetCurrent ().GetTaskRunner ()](const std::string& uri) {
158158 if (!uri.empty ()) {
159- runner->PostTask ([weak, uri]() {
159+ runner->PostTask ([weakSelf, uri]() {
160+ FlutterDartVMServicePublisher* strongSelf = weakSelf;
160161 // uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port
161162 // number.
162- if (weak ) {
163- NSURL * url = [[[ NSURL alloc ]
164- initWithString: [NSString stringWithUTF8String: uri.c_str ()]] autorelease ];
165- weak. get () .url = url;
166- if (weak. get () .enableVMServicePublication ) {
167- [[weak. get () delegate ] publishServiceProtocolPort: url];
163+ if (strongSelf ) {
164+ NSURL * url =
165+ [[ NSURL alloc ] initWithString: [NSString stringWithUTF8String: uri.c_str ()]];
166+ strongSelf .url = url;
167+ if (strongSelf .enableVMServicePublication ) {
168+ [[strongSelf delegate ] publishServiceProtocolPort: url];
168169 }
169170 }
170171 });
@@ -190,15 +191,9 @@ + (NSData*)createTxtData:(NSURL*)url {
190191}
191192
192193- (void )dealloc {
193- // It will be destroyed and invalidate its weak pointers
194- // before any other members are destroyed.
195- _weakFactory.reset ();
196-
197194 [_delegate stopService ];
198- [_url release ];
199195
200196 flutter::DartServiceIsolate::RemoveServerStatusCallback (_callbackHandle);
201- [super dealloc ];
202197}
203198@end
204199
0 commit comments