Flutter iOS 14.0 build error: Failed to register observatory port with mDNS - ios

I am implementing a mobile app using Flutter. When I try to run the app on iOS real device from Xcode, I get this error:
[VERBOSE-2:FlutterObservatoryPublisher.mm(115)] Failed to register observatory port with mDNS.
The app runs fine as long as the device is connected to the Mac and running from Xcode. But when I try to open it from the device Home Screen directly, it crashes.
This issue happens on iOS 14.0 and higher. It works fine on iOS 13.x.

add this property info.plist
<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>

I was able to fix it. This is how I did it.
For you to fix this error. open the iPhone simulator then run your flutter project. then go to System Preferences > Security & Privacy > General Tab. You need to give permission to iproxy(I can't remember the file name but you need to give that file permission to run). After it has successfully run on your simulator. Plug your iPhone follow the steps again.

I debug an (object-c based) flutter project, I like to launch it in Xcode, I find it more fast launching app in Xcode than 'flutter run' command in terminal. then I like to 'flutter attach' to it for hot reload.
I encountered this error very often.
It seems to touch the AppDelegate.m file forcing it to be re-compiled can fix this problem....

Flutter Official Documentation
According the Flutter official documentation:
On iOS 14 and higher, enable the Dart multicast DNS service in the Debug version of your app...
One way to do this is to maintain a separate copy of your app’s Info.plist per build configuration.
Rename your app’s Info.plist to Info-Debug.plist. Make a copy of it called Info-Release.plist and add it to your Xcode project.
In Info-Debug.plist only add the key NSBonjourServices and set the value to an array with the string _dartobservatory._tcp. Note Xcode will display this as “Bonjour services”.
In your target’s build settings, change the Info.plist File (INFOPLIST_FILE) setting path from path/to/Info.plist to path/to/Info-$(CONFIGURATION).plist.

It's a few days I'm dealing (without a solution) with this problem.
If you have any useful information, here you can share it (or, maybe, find it).
At the moment, I'm working on a workaround, that I will share in that thread ASAP.

Here is the original documentation
On iOS 14 and higher, enable the Dart multicast DNS service in the Debug version of your app to add debugging functionalities such as hot-reload and DevTools via flutter attach.
In Info.plist only add the key NSBonjourServices and set the value to an array with the string _dartobservatory._tcp. Note Xcode will display this as “Bonjour services”.
Optionally, add the key NSLocalNetworkUsageDescription set to your desired customized permission dialog text.
The original documentation mentions that this shouldn't be used in the Release version and also provides some instructions how to enable only for Debug releases.
Warning: This service must not be enabled in the Release version of your app, or you may experience App Store rejections.

Related

Can't get debug token for Firebase App Check for my Flutter iOS App

So I recently started setting up app check for my existing Flutter project (for both android and iOS platforms). I've had no problem with android's "Play Integrity", got the necessary debug token, and can successfully send and retrieve data to/from firestore (app check for firestore is currently enforced for my project).
The problem is, I can not get such a debug key for my iOS app. I will list the sources I've used and what I've tried so far.
I have firebase_app_check: ^0.1.1+8 installed via pubspec.yaml
I also added pod 'FirebaseAppCheck' to my Podfile
I have the necessary initialization code in my main.dart: await FirebaseAppCheck.instance.activate(...);
For "DeviceCheck", I am using THE SAME private key that I am using
for "Sign in With Apple" (which I have implemented successfully). I
have also enabled the checkbox for DeviceCheck in the settings of
that private key (in Apple Developer).
For my App ID (Apple Developer > Identifiers > App IDs), I have also
enabled the checkbox for "App Attest".
I have put "-FIRDebugEnabled" as an argument passed on launch in
XCode > Product > Scheme > Edit Scheme.
I always uninstall my app from my iOS simulator (iOS 16.2) or real device (iOS 16.1.2),
before trying again, because I have read across multiple forums that
the debug token only gets printed to the output the first time you
run your app.
I have also added these 4 lines of code in my AppDelegate.swift from here:
#if DEBUG
let providerFactory = AppCheckDebugProviderFactory()
AppCheck.setAppCheckProviderFactory(providerFactory)
#endif
Official firebase docs "iOS+ (App Attest)":
I have NOT copied ANY code from this page of the official docs, as I assume it's for native iOS apps only, and not for flutter, and I don't know where exactly I would have to put that code. I have only added the pod dependency and run pod install.
I don't have a .entitlements file.
So after all those steps, I'm apparently supposed to expect to find a debug token in my run output, as in:
Yet the only relevant output I can find is the following:
Runner[72719:33546579] 10.3.0 - [FirebaseFirestore][I-FST000001] AppCheck failed: 'The operation couldn’t be completed. (com.apple.devicecheck.error error 1.)'
If it matters:
I have NOT YET uploaded my iOS app to apple developer, app store connect or whatever (I'm not yet familiar with the process of publishing to the app store).
Neither have I uploaded my android app to Google Play console or created an app there (for this project).
Don't tell me anything about firestore rules. I already had that set up long ago, and everything worked just fine before I started integrating App Check.
Don't recommend any 3rd party plugins to me, I will only use official ones.
The firebase documentation says:
Tip: Confirm in your Xcode project's build settings that it passes the DEBUG flag to the Swift compiler
Try removing the '#if DEBUG' and '#endif' and run the app.
If it works, it mean you have missed that step
I was not able to find that build setting, so i just removed those lines from the AppDelegate, but i need to keep in mind to remove the other 2 lines while building the release mode
See this answer on the flutterfire Github issues page. Basically, call setAppCheckProviderFactory before GeneratedPluginRegistrant.register(with: self) in the app delegate file. I was investigating the same issue and it fixed it for me (the debug token was instantly printed out in Xcode's debug output). Hope it helps you as well!

React native app stuck on splash screen on device but works in simulator

My React Native app works in the XCode simulator with no issues, but when I run in a physical device, my iPhone, there's a problem. The app launches and gets stuck on the React Native splash screen, the after 10-15 seconds the app crashes/closes. What's the cause of this and how can I prevent it?
It seems that I have found the problem. According to https://facebook.github.io/react-native/docs/running-on-device, when you build and run the app on your device, your app will load js files from the packager on your computer, so you can live reload your app. That means your device has to be connected to your computer or has to be in the same wifi network as your computer. If your device can't access the packager, it will stuck on the splash screen and quit.
To run on your device reliably, edit build schema and build release version.
For me when I build, it was working fine in simulator however, in actual device only splash screen was coming and nothing else.
This was because my build configuration was debug mode which is default I guess, I had to change release/build configuration from debug to release and everything work as expected.
Upvote it if this helps :)
Yep I had WiFi on my phone disabled. Enabled WiFi and boom back in business
It should be perfectly possible to run the app in debug, on the device, without the packager attached! You have to use react-native bundle to create an offline bundle, and add it to your Xcode project. Then your app should fall back to that bundle when the packager is not available.
This used to be in the Deploying to Device FB docs, not sure why it's not there anymore.
Sample call (our index.ios.js is placed in ./dist by TypeScript):
react-native bundle --dev true --assets-dest ./ios --entry-file ./dist/index.ios.js --platform ios --bundle-output ios/main.jsbundle
Also, it's apparently necessary to tell your app to run directly from the bundle rather than try to access the development server, which seems to cause the timeout (we had the same issue as OP).
Comment out this line:
jsCodeLocation = // whatever
And add this line:
jsCodeLocation = [[NSBundle mainBundle] URLForResource:#"main" withExtension:#"jsbundle"];
I tried disconnecting my iPhone from the Internet, the problem disappeared in later launches.
So something is trying to do network stuff and causing the delay.
It's a quick fix, but will do until we find the specific culprit.
I was having the same issue.
What I did was in Xcode go to Products -> Scheme -> Edit Scheme -> Select the Run tab -> Change the build configuration to Release ( default it was debug mode ) and run the app in the device.
It was much faster and run it as like a native app.
Just experienced this and after an hour of debugging realized I had recently enabled my systems firewall and set it to "Block all incoming connections".
Weird thing is that android was functioning fine on a physical device, however iOS on a physical device was not able to connect to the RN server. Relaxed the firewall rules and now iOS can connect to the RN server.
You probably need to sign the app.
Under the Project navigator, click on your app. Then select your target from the project and targets list. Within the "General" tab, find the 'Signing' section. You'll need to specify a team here.
See this link for more info: https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/LaunchingYourApponDevices/LaunchingYourApponDevices.html#//apple_ref/doc/uid/TP40012582-CH27-SW4
I faced this issue where I was react-native-splash-screen. After removing it, it is working
This issue could raise due to the following possibilities:
Your run schema set to release instead of debug, so always expect to load main.jsbundle, instead of running from the debug server. Change it by Product->Schema-> Edit Schema->Run-> Build Configuration: Debug
Check on Xcode log that any message like NSURLConnection finished with error - code -1004 or NSURLConnection finished with error - code -1022.
Go to Project->Target->Build Phases-> + -> New Run Script Phase
(-1004) You have configured your XCode project from sketch and forgot to enter the react-native xcode script on Build Phases:
For the below version of React Native 50:
export NODE_BINARY=node
../node_modules/react-native/packager/react-native-xcode.sh
For the higher version of React Native 50:
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh
(-1022) Your app ATS issue, check on Info.plist, and you can turn off ATS using below code:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
For me I am using firebase framework on my project. I forgot the add GoogleService-Info.plist file to my xcode project. After add it problem gone away.
Happened to me on my iOS device. I was connected to 4G, not WiFi. I connected to WiFi and it started working immediately.
I am facing same issue when I upload release on TestFlight, so what I did is
react-native link react-native-splash-screen
because some how my splash screen plugin is unlinked. This works for me.
Best check with all outgoing calls. This might happened if you do call an http request to fetch user for example or during fetching user from storage.
If this call returned error, you'll be stuck in Splash screen.
Additionally, imagine that you have navigation that uses these calls it will be worse.
All the solutions above do not work for me.
It's really weird in my situation. The router in my company sends both 2.4G and 5.0G wifi. Only connecting to the 2.4G wifi works when debug on real device.
For me,
I have followed below steps:
removed node_modules and reinstalled node_modules
restarted metro server
re-installed the app
In my case app stack on splash screen on both (debug & release) schemes of build.
Problem was in Capabilities for push Notification and Firebase. Just add this one. How you can do this
May be it'll help you:)
Delete node_modules folder
Then run
yarn or npm install

dyld`__abort_with_payload: Without an error message

When I start my app with Xcode, I have a crash, but without an error.
The app is just stopping on this thread:
What can I do to have more information about the issue?
If you are using custom frameworks, you need to put it inside the "Embedded Binaries" section located in the Xcode project under the tab Target / General.
For me a simple Clean and Rebuild sorted it out.
This problem appeared after a system update up to macOS 10.15.2 beta (Catalina). Disabling "Thread Sanitizer" solved the issue (Xcode 11.2). Now I can't use Thread Sanitizer and have to wait for the next OS update.
Adding the framework to the embedded binary asset list fixed this. Here is what the setup of a foreign framework looks like in final form in the Xcode GUI as an Embedded Framework (Xcode 9.2, personally I like a visual breadcrumb trail better ;-) ):
Did Apple intentionally crash the runtime to somehow tell the developer about the problem that you cannot use non-Apple frameworks as simply linked frameworks in iOS development? It would be better to have it come up as a build error I would think... with a button that said "move it!"
The use of Embedded Binaries keeps the end user from having to add the Framework independently of your app (or have you do with an installer). In the case of the iPhone (iOS), that is impossible, but on macOS, it is possible, but it can get messy fast.
For the end user, it is much nicer to simply drag and drop an app to install it on macOS, which is where embedded becomes a benefit. Embedding also avoids the classic "DLL conflicts" of having external versions of your framework to manage. (Disk space is cheap, but my customer's time is precious.)
I fixed the error in my project just now!
If you are using the Swift framework in an Objective-C project, I advice you to change the build settings.
Set the Always Set Embed the Swift Standard Libraries option to Yes. Like this:
It was finally solved!
Making the framework "optional" instead of "required" worked for me.
To answer the original question "What can I do to have more informations about the issue?", this Apple forum thread provides a very simple tip: simply run your crashing app outside Xcode (i.e., stop it from Xcode, then run it manually on your device).
This will produce a crash log containing more details about what happened. You can then review this log from the Xcode Window menu → Devices and Simulators → View Device Logs.
In Xcode 11.1, turn off Do not Embed in Embed & Sign is a nice option.
Credit: mkonovalov's answer and William Cerniuk's answer
Unchecking "Guard Malloc" in diagnostics worked for me.
Continue the execution to see if any message shows up in debugger such as "MyFramework.framework" not found. If that is the case, follow this question: OS X Framework Library not loaded: 'Image not found'
For me Amos Joshua's answer worked.
Make sure you have added your binaries through "Embed Binaries" section.
Make sure you have enabled signing of frameworks in build phase section.
Make sure the embedded frameworks are not symlinks.
You can make the linked frameworks optional instead of required in "Link binary with libraries" phase. This will tell iOS to not look for these frameworks during launch. But anyway you need to fix the errors to use those frameworks!
Check if all the info.plist entries are good. In my case, I was using a Mac info.plist file for iOS. It was looking for some xib file which was not present in the iOS project.
Do a clean and build after any such change. This is required because Xcode does not copy/change these files if they already exist.
Remove the app from iPad and then install. Same reason as 7.
I had just missed applying the "Privacy - Camera Usage Description" in the info.plist file.
I faced the same issue with Xcode 11.3 and macOS v10.15.2 (Catalina) . The app was running well on the device, but not in the simulator. It seems there is an issue with the simulator and the workaround is to disable Thread Sanitizer.
Refer to Xcode 11.3 simulator SIGABRT on launch.
I encountered an error with the same signature (my project was in Objective-C) and discovered I had forgotten to link with the appropriate framework. The error message in the debug log that led to finding the error was:
dyld: Symbol not found: OBJC_CLASS$_SFSafariViewController
For my specific error, adding SafariServices.framework in the Targets → Build Phases → "Link Binary With Libraries" resolved the issue. While you probably don't have the same specific error and resolution, checking the debug log for clues is useful.
Sometimes it happens when you use system frameworks that are accessible only from a later iOS version than your target version. It might be fixed by marking this linked framework as optional.
For example, a project targeted on iOS 11 and being using AuthenticationServices for the iOS 12 AutoFill feature will crash on iOS 11 in the described way.
I had a similar issue that was resolved by a missing permission specification in plist (as weird as it is...).
I've tried to use AVCaptureDevice and it just crashed at starting (my app was very minimal).
Adding Privacy - Camera Usage Description to the info.plist file solved it for me.
I've had this situation after updating Xcode to v10.2.1 and Swift to v5.0.
If you are using Carthage + RxSwift, the new RxSwift uses RxRelay.framework. You should go to your /Carthage/Build directory find that framework and drag it to your project. Don't forget also add it to your carthage copy-frameworks script:
$(SRCROOT)/Carthage/Build/iOS/RxRelay.framework
It was resolved thanks to fred's answer.
I had this issue and didn't have success with the answers.
I was using a custom framework that would connect with Bluetooth devices. So the crash was happening because I had missed applying the "Privacy - Bluetooth Always Usage Description" in the info.plist file.
Check all your permissions fields are set up in the p-list file.
I was facing the same issue. Setting 'Always Embed Swift Standard Libraries' to Yes in Build Settings of my target worked for me.
If you use the Carthage build framework, after dragging the framework to your project, you should add it to General/Embedded Binaries.
I found the right way to resolve it.
Make sure the AppleWWDRCA.cer is set to the system default mode, and then it will work:
If you're using a framework written in Swift in an Objective-C application, you need to include the Swift toolchain in the app that consumes the framework.
The way I've found to do this is to create a dummy Swift file in the app, so that Xcode recognizes Swift and appropriately adds it to the project. You can then delete the dummy file.
Also if you are using custom frameworks, make sure you set the Mach-O type to static library. I read somewhere that iOS doesn't allow dylib. Anyway, this worked for me.
To add to the long list of encounters with this error, it occurs when I am on Xcode 12.2 Beta 2 deploying to my Mac running macOS v10.15.5 (Catalina) with the deployment target set to macOS v11.0 (Big Sur).
This situation happened because I was trying out the Mac Catalyst Tutorial app on adding a SideBar. Switching the target to macOS v10.15.5 eliminated the error and launched the app properly.
I faced this issue on iOS 14.5 when playing/implementing ATT (App Tracking Transparency) and have yet to add a usage description in file info.plist on why user tracking is needed.
The app crashes whenever the settings "Allow Apps to Request to Track" was enabled (when disabled, everything worked well).
The crash in Xcode provided no clues, except
libsystem_kernel.dylib`__abort_with_payload: (SIGABRT)
CoreSimulator 757.5 - Device: iPhone 11 (29AD27B2-6EC0-4B9C-8C8C-C5450695A19C) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 11
Using the answer from fred's answer and getting the crash log from the actual device yielded this clue which was extremely helpful.
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: TCC, This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSUserTrackingUsageDescription key with a string value explaining to the user how the app uses this data.
Triggered by Thread: 1
I fixed it by changing "Embed & Sign" to "Embed without Signing" under General > Frameworks, Libraries and Embedded Content.
I didn't think this applied to me because I wasn't using the camera, but it did.
Many answers reference adding a Usage Description to Info.plist. I didn't know there are many more cases where a usage description is necessary (besides just the camera), see this link.
The link lists these services as needing a usage description or will cause this error:
Calendar, Contact, Reminder, Photo, Bluetooth Sharing, Microphone, Camera, Location, Heath, HomeKit, Media Library, Motion, CallKit, Speech Recognition, SiriKit, and TV Provider.
Add an entry to Info.plist, start typing "Privacy" as the key, and you will see all the available options pop up.
I've just had the same issue and the reason why was due to the fact that I've revoked my Developer Certificates and created new ones with Xcode 10, after a fresh macOS v10.14 (Mojave) update (for some reason, it deleted all login credentials and outdated some keychain certificates).
So, all I had to do was to remove the installed apps from my device and run them through Xcode again, in order for it to install the right new Provisioning Profile in my device :)
Actually, I had the issue with Xcode 11.3.1 and Thread Sanitizer was already turned off as mentioned in previous answers.
In my case, the issue was I used to have different Xcode versions in my Application folder like this:
/Applications/xcode11.3.1/Xcode.app
/Applications/xcode11.3/Xcode.app
/Applications/xcode10.1/Xcode.app
and
/Applications/Xcode.app - was 11.2
The build system looks on the /Applications/Xcode.app file by default. So bringing Xcode 11.3.1 to the /Applications/Xcode.app finally resolve the problem.
The same issue happened with me. I had iOS 14 Beta and the problem was fixed when I updated it to the official version.
I have fixed my error in my project.
I checked the other threads when the error happened. I found my error is about the camera.
Add the Camera privacy in the Info.plist file.
Open the info.plist file.
Add a new key called "Privacy - Camera Usage Description" and enter a string that describes why the app need camera. The describes will display when your app need to use the privacy.

Run app phonegap with xcode on jailbroken iPhone

I developed an app with phonegap, and I hate to try on a apple device. I've jailbroken my iPhone5s for try my app without pay apple.
I follow this guide, but seems does't work:
On your Jailbroken device install AppSync Unified 5.2-1 (or later)
from AngelXWind’s repo. Don’t use any other AppSync, and if you have
others, be sure to remove them. Open
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/SDKSettings.plist
and change AD_HOC_CODE_SIGNING_ALLOWED to YES. You may need to
duplicate it to the desktop, change it, save it, then drag and drop
back into the original folder because OS X let you edit the file in
place. If XCode was running, restart XCode. Change your Project and
Target settings to “Ad Hoc Code Sign” in Build Settings Tell XCode to
run app on iPhone. At this point XCode will put app on your iDevice,
but can’t debug because it can’t attach to the process. The app will
start then close immediately. You can now manually start the app on
the phone now though. To enable debugging: In your project select
File>New File Property List and create a file called
“Entitlements.plist”. Add “Can be debugged” or “get-task-allow” (both
do the same thing) and set the value to YES. Now change your Project
and Target Code Signing Entitlements (In Build Settings) to
“Entitlements.plist” (you have to type it in). Now XCode can run and
debug the app. Good luck
This is the link of the guide.
When I run app, XCode tell me "Build Success", and on top it says :"Running on Iphone". If I open detail, it say: "Preparing to install " with a loading circle. It's 20 minute that is preparing to install my app.
How can I fix this problem?

Can't run Lister app sample code (Swift) from Apple's website

I tried to download and run the Lister app sample code which was presented at WWDC for the session 406: Integrating Swift With Objective-C. (I am running XCode 6.1 on Yosemite and this is the most updated version of the Lister app from the sample code page in Apple).
https://developer.apple.com/library/ios/samplecode/Lister/Introduction/Intro.html
However I was unable to run the app in XCode which are best show in the attached screenshot.
The app doesn't have the Run and Stop buttons enabled. They are greyed out. Never had this before for any other app.
The icons for the Lister app is not showing. Instead there is this new Settings-like icon which I have never seen and have no idea what it means.
There is a ReadMe.txt file in the project that you downloaded. Have you read it because I had the same problem and by reading it, my problems were solved.
Regards
The QuickStart guide included in the project gives the key setting to change in the Build Settings to enable iCloud.
In the User-Defined section, double-click on com.example.apple-
samplecode to edit the LISTER_BUNDLE_PREFIX value.
Change this prefix to a globally unique reverse DNS string for your own
organization’s name, such as com.somecompany.lister.

Resources