5#define FML_USED_ON_EMBEDDER
12- (instancetype)initWithEnableVMServicePublication:(
BOOL)enableVMServicePublication {
19#import <TargetConditionals.h>
42#include "flutter/fml/logging.h"
43#include "flutter/fml/message_loop.h"
44#include "flutter/fml/platform/darwin/scoped_nsobject.h"
45#include "flutter/runtime/dart_service_isolate.h"
46#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
51- (void)publishServiceProtocolPort:(NSURL*)uri;
56+ (NSData*)createTxtData:(NSURL*)url;
59@property(readonly) NSObject<FlutterDartVMServicePublisherDelegate>*
delegate;
60@property(nonatomic, readwrite) NSURL*
url;
69 DNSServiceRef _dnsServiceRef;
74 DNSServiceRefDeallocate(_dnsServiceRef);
75 _dnsServiceRef = NULL;
79- (void)publishServiceProtocolPort:(NSURL*)url {
81 FML_LOG(INFO) <<
"Publish Service Protocol Port";
82 DNSServiceFlags
flags = kDNSServiceFlagsDefault;
83#if TARGET_IPHONE_SIMULATOR
85 uint32_t interfaceIndex = if_nametoindex(
"lo0");
88 uint32_t interfaceIndex = 0;
90 const char* registrationType =
"_dartVmService._tcp";
92 const char* domain =
"local.";
93 uint16_t
port = [[url port] unsignedShortValue];
96 int err = DNSServiceRegister(&_dnsServiceRef,
flags, interfaceIndex,
98 registrationType, domain, NULL, htons(
port), txtData.length,
102 DNSServiceSetDispatchQueue(_dnsServiceRef, dispatch_get_main_queue());
106 FML_LOG(
ERROR) <<
"Failed to register Dart VM Service port with mDNS with error " << err <<
".";
107 if (@available(iOS 14.0, *)) {
108 FML_LOG(
ERROR) <<
"On iOS 14+, local network broadcast in apps need to be declared in "
109 <<
"the app's Info.plist. Debug and profile Flutter apps and modules host "
110 <<
"VM services on the local network to support debugging features such "
111 <<
"as hot reload and DevTools. To make your Flutter app or module "
112 <<
"attachable and debuggable, add a '" << registrationType <<
"' value "
113 <<
"to the 'NSBonjourServices' key in your Info.plist for the Debug/"
114 <<
"Profile configurations. " <<
"For more information, see "
115 <<
"https://flutter.dev/docs/development/add-to-app/ios/"
116 "project-setup#local-network-privacy-permissions";
121 DNSServiceFlags
flags,
122 DNSServiceErrorType errorCode,
127 if (errorCode == kDNSServiceErr_NoError) {
128 FML_DLOG(INFO) <<
"FlutterDartVMServicePublisher is ready!";
129 }
else if (errorCode == kDNSServiceErr_PolicyDenied) {
131 <<
"Could not register as server for FlutterDartVMServicePublisher, permission "
132 <<
"denied. Check your 'Local Network' permissions for this app in the Privacy section of "
133 <<
"the system Settings.";
135 FML_LOG(
ERROR) <<
"Could not register as server for FlutterDartVMServicePublisher. Check your "
136 "network settings and relaunch the application.";
146- (instancetype)initWithEnableVMServicePublication:(
BOOL)enableVMServicePublication {
148 NSAssert(
self,
@"Super must not return null on init.");
151 _enableVMServicePublication = enableVMServicePublication;
152 __weak __typeof(
self) weakSelf =
self;
159 runner->PostTask([weakSelf, uri]() {
160 FlutterDartVMServicePublisher* strongSelf = weakSelf;
165 [[NSURL alloc] initWithString:[NSString stringWithUTF8String:uri.c_str()]];
166 strongSelf.url = url;
167 if (strongSelf.enableVMServicePublication) {
168 [[strongSelf delegate] publishServiceProtocolPort:url];
178+ (NSString*)serviceName {
179 return NSBundle.mainBundle.bundleIdentifier;
182+ (NSData*)createTxtData:(NSURL*)url {
185 NSString*
path = [[url path] substringFromIndex:MIN(1, [[url path] length])];
186 NSData* pathData = [path dataUsingEncoding:NSUTF8StringEncoding];
187 NSDictionary<NSString*, NSData*>* txtDict = @{
188 @"authCode" : pathData,
190 return [NSNetService dataFromTXTRecordDictionary:txtDict];
194 [_delegate stopService];
static CallbackHandle AddServerStatusCallback(const DartVMServiceServerStateCallback &callback)
Add a callback that will get invoked when the VM Service starts up. If the VM Service has already sta...
static bool RemoveServerStatusCallback(CallbackHandle handle)
Removed a callback previously registered via AddServiceStatusCallback.
static void EnsureInitializedForCurrentThread()
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
FlutterSemanticsFlag flags
#define FML_DLOG(severity)
#define FML_LOG(severity)
static void DNSSD_API RegistrationCallback(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *name, const char *regType, const char *domain, void *context)
BOOL enableVMServicePublication
NSData * createTxtData:(NSURL *url)
NSObject< FlutterDartVMServicePublisherDelegate > * delegate
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library name