diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index bf1e757687..992a1c8305 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -228,6 +228,15 @@ FLUTTER_EXPORT */ @property(nonatomic, readonly) FlutterBasicMessageChannel* settingsChannel; +/** + * The `NSURL` of the observatory for the service isolate. + * + * This is only set in debug and profile runtime modes, and only after the + * observatory service is ready. In release mode or before the observatory has + * started, it returns `nil`. + */ +@property(nonatomic, readonly) NSURL* observatoryUrl; + @end #endif // FLUTTER_FLUTTERENGINE_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 50208e65a0..f99c346ea1 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -207,6 +207,10 @@ return _settingsChannel.get(); } +- (NSURL*)observatoryUrl { + return [_publisher.get() url]; +} + - (void)resetChannels { _localizationChannel.reset(); _navigationChannel.reset(); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h index 68f97c6b66..387176f76e 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h @@ -9,6 +9,8 @@ @interface FlutterObservatoryPublisher : NSObject +@property(nonatomic, readonly) NSURL* url; + @end #endif // FLUTTER_FLUTTEROBSERVATORYPUBLISHER_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm index 38c92fa1ce..67b961da37 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm @@ -36,6 +36,7 @@ @end @implementation FlutterObservatoryPublisher { + fml::scoped_nsobject _url; #if TARGET_IPHONE_SIMULATOR DNSServiceRef _dnsServiceRef; #else // TARGET_IPHONE_SIMULATOR @@ -46,6 +47,10 @@ std::unique_ptr> _weakFactory; } +- (NSURL*)url { + return _url.get(); +} + - (instancetype)init { self = [super init]; NSAssert(self, @"Super must not return null on init."); @@ -92,15 +97,14 @@ } // uri comes in as something like 'http://127.0.0.1:XXXXX/' where XXXXX is the port // number. - NSURL* url = - [[[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]] autorelease]; + _url.reset([[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]]); NSString* serviceName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]; // Check to see if there's an authentication code. If there is, we'll provide // it as a txt record so flutter tools can establish a connection. - auto path = std::string{[[url path] UTF8String]}; + auto path = std::string{[[_url path] UTF8String]}; if (!path.empty()) { // Remove leading "/" path = path.substr(1); @@ -116,7 +120,7 @@ uint32_t interfaceIndex = if_nametoindex("lo0"); const char* registrationType = "_dartobservatory._tcp"; const char* domain = "local."; // default domain - uint16_t port = [[url port] intValue]; + uint16_t port = [[_url port] intValue]; int err = DNSServiceRegister(&_dnsServiceRef, flags, interfaceIndex, [serviceName UTF8String], registrationType, domain, NULL, htons(port), txtData.length, @@ -131,7 +135,7 @@ NSNetService* netServiceTmp = [[NSNetService alloc] initWithDomain:@"local." type:@"_dartobservatory._tcp." name:serviceName - port:[[url port] intValue]]; + port:[[_url port] intValue]]; [netServiceTmp setTXTRecordData:txtData]; _netService.reset(netServiceTmp); [_netService.get() setDelegate:self];