@@ -40,10 +40,12 @@ - (instancetype)initWithEnableVMServicePublication:(BOOL)enableVMServicePublicat
40
40
#include < net/if.h>
41
41
42
42
#include " flutter/fml/logging.h"
43
- #include " flutter/fml/memory/weak_ptr.h"
44
43
#include " flutter/fml/message_loop.h"
45
44
#include " flutter/fml/platform/darwin/scoped_nsobject.h"
46
45
#include " flutter/runtime/dart_service_isolate.h"
46
+ #import " flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
47
+
48
+ FLUTTER_ASSERT_ARC
47
49
48
50
@protocol FlutterDartVMServicePublisherDelegate
49
51
- (void )publishServiceProtocolPort : (NSURL *)uri ;
@@ -54,7 +56,7 @@ @interface FlutterDartVMServicePublisher ()
54
56
+ (NSData *)createTxtData : (NSURL *)url ;
55
57
56
58
@property (readonly , class ) NSString * serviceName;
57
- @property (readonly ) fml::scoped_nsobject< NSObject <FlutterDartVMServicePublisherDelegate>> delegate;
59
+ @property (readonly ) NSObject <FlutterDartVMServicePublisherDelegate>* delegate;
58
60
@property (nonatomic , readwrite ) NSURL * url;
59
61
@property (readonly ) BOOL enableVMServicePublication;
60
62
@@ -139,32 +141,30 @@ static void DNSSD_API RegistrationCallback(DNSServiceRef sdRef,
139
141
140
142
@implementation FlutterDartVMServicePublisher {
141
143
flutter::DartServiceIsolate::CallbackHandle _callbackHandle;
142
- std::unique_ptr<fml::WeakPtrFactory<FlutterDartVMServicePublisher>> _weakFactory;
143
144
}
144
145
145
146
- (instancetype )initWithEnableVMServicePublication : (BOOL )enableVMServicePublication {
146
147
self = [super init ];
147
148
NSAssert (self, @" Super must not return null on init." );
148
149
149
- _delegate. reset ( [[DartVMServiceDNSServiceDelegate alloc ] init ]) ;
150
+ _delegate = [[DartVMServiceDNSServiceDelegate alloc ] init ];
150
151
_enableVMServicePublication = enableVMServicePublication;
151
- _weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterDartVMServicePublisher>> (self);
152
+ __weak __typeof (self) weakSelf = self ;
152
153
153
154
fml::MessageLoop::EnsureInitializedForCurrentThread ();
154
155
155
156
_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) {
158
158
if (!uri.empty ()) {
159
- runner->PostTask ([weak , uri]() {
159
+ runner->PostTask ([weakSelf , uri]() {
160
160
// uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port
161
161
// 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];
162
+ if (weakSelf ) {
163
+ NSURL * url =
164
+ [[ NSURL alloc ] initWithString: [NSString stringWithUTF8String: uri.c_str ()]];
165
+ weakSelf .url = url;
166
+ if (weakSelf .enableVMServicePublication ) {
167
+ [[weakSelf delegate ] publishServiceProtocolPort: url];
168
168
}
169
169
}
170
170
});
@@ -190,15 +190,9 @@ + (NSData*)createTxtData:(NSURL*)url {
190
190
}
191
191
192
192
- (void )dealloc {
193
- // It will be destroyed and invalidate its weak pointers
194
- // before any other members are destroyed.
195
- _weakFactory.reset ();
196
-
197
193
[_delegate stopService ];
198
- [_url release ];
199
194
200
195
flutter::DartServiceIsolate::RemoveServerStatusCallback (_callbackHandle);
201
- [super dealloc ];
202
196
}
203
197
@end
204
198
0 commit comments