Dev mode vs production mode in React Native (Xcode) - ios

Memory errors when testing on physical iPhone
I currently am experiencing memory issues when I run my react-native app on a physical device (iPhone connected through USB cable). I have tracked it down to too many console.log outputs. I have come across a couple of different solutions:
On this [React-Native page][1] Facebook recommends using the babel-plugin-transform-remove-console plugin. It is to be installed to work in dev mode only npm i babel-plugin-transform-remove-console --save-dev with the following code in .babelrc:
{
"env": {
"production": {
"plugins": ["transform-remove-console"]
}
}
}
Note: I do not have a .babelrc file. I only have a babel.config.js file.
Some people are recommending using:
if (!DEV) {
console.log = () => {};
}
I believe this is setting any instance of console.log to an empty object if you are not in DEV mode.
Issues with getting accepted at the App Store
Apple is rejecting my app due to a bug at the point this memory error is happening. So, I am assuming that the console.log() statements are being compiled with the app and that they are encountering the memory error as well. They have not told me that there is a memory error, but just that it is not working at that particular point.
DEV mode vs Production mode
With options 1 and 2 above both assume a production mode vs a dev mode. However, when I compile the app with Xcode to upload to the App Store, how do I know what mode it is going to be in?
When I select Product>Archive from Xcode does that automatically put it in Production mode instead of Dev mode? Or is there something else I am needing to do to ensure that it is compiling it in production mode?

When you archive your app in Xcode it will be in "PROD" mode (aka release mode). In Xcode you can run your app in both DEV (aka debug mode) and PROD in Xcode. That will make it easier for you to get to the bottom of this memory issue.
To do this:
1. select the scheme you're working with in the top bar, click "Edit scheme"
2. and then set "Build configuration" to Release, and uncheck "Debug executable"
You can select any Simulator or connected device press the "Play" button to run a release build, with all the performance optimizations that come with that.

what you have after doing archiving is a production code.
And in my cases, my production app got stuck when it stumbles to a code which logging a React.createRef() object. In dev mode everything is ok.
You may try using if(__DEV__){...} to log anything, as all those console.log still fire in production

Related

Deploying Xamarin.Forms app to iOS: MT1006 EOF Error (error: 0xe800000e)

I am trying to run a Xamarin.Forms app on my iPad and getting the following error:
Launch failed. The app 'AppIOS' could not be launched on 'My iPad'. Error: error MT1006: Could not install the application '/Users/mycompany/Library/Caches/Xamarin/mtbs/builds/AppIOS/someguid/bin/iPhone/Debug/my.app' on the device 'My iPad': EOF Error (error: 0xe800000e).. Please check the logs for more details.
This app has previously ran fine on the same device. The iOS build and deployment process seems very unstable so it often takes multiple attempts so I'm used to having to restart Visual Studio, the Mac it builds on and the iPad and generally wasting a whole lot of time. I have restarted everything involved here multiple times but this error persists. I have checked the device logs and there are no related messages or even any messages at the appropriate times.
I'm using Visual Studio 2017 (15.9.4), Xamarin.iOS and Xamarin.Mac SDK (12.2.1.12), building on a Mac Mini running macOS Mojave and XCode 10.1, deploying to an iPad Air (A1474) running iOS 12.1.1. As far as I'm aware there have been no updates to any of these since I last had it working. The UWP version of the app runs fine.
I can find a lot of MT1006 issues but none with EOF Error (error: 0xe800000e) and I can find no information about this specific error at all. Can anyone enlighten me on what this means?
Sounds overly simple, but I just had this issue and I solved it by restarting the iOS device and redeploying it. Specifically, I was deploying to an iPod 6th Gen and I held the power and home buttons until the screen turned black, this is more of a hard restart. Then let the device reboot and try deploying again.
NOTE: Don't hold the power and home buttons too long, because if you do, the iPod will go into a factory reset restart.
Try pulling up the device in Xcodes' devices tab. I did and realized the device had an error within the tab. I then disabled the "Connect via network" button, then things started to work properly.
I am agree, Xamarin build environment on iOS part is very buggy.
In any case of unknown error in such config: VS<->MAC<->iOS Device try these steps:
Try to switch Off and On Mac wifi.
Reconnect VS to Macbook and Macbook to IPhone.
Delete bin and obj folders on Macbook
Check your PList and Entitlements file(as example wrong aps-environment setting can cause installing errors)
Check your sign project settings
5a. Check your provisoning profile term
unistall application from ios
rebuild and run project again
I'll appent new lines in case i'll remember something else.
What you described happened to me and solved by 1,2,7

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

How do you debug an issue with a release mode build in iOS?

I am working on an iOS app and I have noticed a bug that is only reproducible when the app is built in release mode. The only way I have found to run a release mode app that I have built is by building an archive, signing it with my debug profile, and doing an ad-hoc deployment to my device. Using this method however I can't attach with a debugger, and I'm not even sure if I could attach it if it would work well after the release build had run the optimizer on the code.
Does anyone know of a good way to debug an issue that is only reproducible when an app is build in release mode?
Normally Debug builds have optimisation disabled (-O0) to make debugging easier, whereas Release builds have optimisation enabled (-O3 or -Os), which makes the code run much faster, but also makes debugging harder (but not impossible). You can just go into the build settings in Xcode in the Debug configuration and temporarily turn up the optimisation level - this will keep all the other debug goodies (symbols etc) but hopefully also flush out the Release mode bug. (Don't forget to reset the optimisation level to -O0 in the Debug configuration when you're done!)
Go to "Project" command in an Xcode application menu and chose "Edit Scheme"(Shortcut: ⌘< )
Select "Run Project name" in left pane
In right pane, under "Info" tab change "Build Configuration" to "Release"
You can not run an app in release mode while have having debugging turned on. That is not intended.
When running an app in release mode you have to find a different way to observe the behaviour of your app (e.g. using alerts).
Additionally you will have to trust the distribution profile on your device. Xcode will notify and guide you with an alert message on the first run.
To debug an iOS application in release mode modify the settings:
Build Settings -> Deployment -> Deployment Post Processing -> Release -> set value as "NO"
Set 'Deployment Post Processing: Release' value as 'No'
I had to briefly turn on automatic signing in order to accomplish this. You aren't able to build directly on device with an iOS Distribution certificate (you need an iOS Development certificate) and you can't release to the App Store with an iOS Development certificate (you need an iOS Distribution certificate).
My debug mode was configured to use an iOS Development certificate to build directly on device. My release mode was configured to use an iOS Distribution certificate to allow the app to be installed on all devices. In order to run in release mode on device I switched to automatic code signing briefly to test. Once I was done testing, I used git to revert to the previous Xcode configuration.
Not the most elegant way, but it got the job done.

Ad Hoc test install failing

I have a project I can successfully build/install using developer/debug to a device or simulator.
When I make an ad hoc build i can build-run onto the simulator, but not onto the device.
I'm trying to perform a direct install because the ad hoc installed app is crashing (nil added to array) where the debug version is not.
I also have tried to attach to the running ad hoc installed app. The app will run indefinitely (but crash if i perform a particular use case.) But if I attempt to attach to the running app, it will crash.
It happens to be a Box2d/Cocos2d application - but i don't have any reason to think they are the cause. Xcode 4.3.2, iPhone4 iOS 5.1
the message when build-and-run is attempted:
error: failed to launch '/Users/bshirley/Library/Developer/Xcode/DerivedData/foo-bar-evrbckppmbsspqhezhleaxkmymxn/Build/Products/Adhoc-iphoneos/foo-bar.app/foo-bar' -- failed to get the task for process 6892
Anyone have some insight into the problem or tracking it down?
Edit, I thought I'd add some key words so searches might be more likely to find:
One issue with diagnosing the post-mortem crash was that the stack trace was not symbolized in the Device Logs of the Organizer in Xcode. That left me with 6+ deep stack trace w/i my code and no real reason to determine where it actually was.
If it is a release build, the app will (in a default setup) have a flag preventing outside processes from hooking into it (for security reasons). This includes the debugger. If you try, you will get the exact error message you indicate.
EDIT Sorry, small error. A release build alone will not cause this. A build with an adhoc certificate will cause this, because it is meant for final install on a device (not debugging).
If borrrden is correct (and it seems reasonable that he is, connecting one app to a signed running app would be a security issue), I can't actively debug the adhoc app.
The most useful thing i found for tracking down this issue, is Build Settings -> Symbols Hidden by Default - this value is only NO for debug. Setting it for NO on adhoc allowed me to see the entire stack trace when inspecting the Device Logs in the Xcode Organizer.
That led me to the particular method that was invoking the crash causing issue. Which led to the question why wasn't it crashing in the debug build. Didn't have time to diagnose that, just fix the problem.

use instruments - leaks with a device

I'm starting to use Instruments-Leaks with an iPhone 3G. When I try to run the app with Instruments on the iPhone I obtain
Target failed to run: Remote exception encountered: 'Failed to get task for pid 280'
Ideas?
The only time I succeed in running the app with instruments it run very slow, I couldn't test it.
What are the steps to run the app on the device searching for leaks?
The solution for me was to make sure that my Profile scheme was using the "debug" and not "release" build configuration.
In Xcode 4 select Product/Edit Scheme from the top menu
then click on the "profile" button on the left.
On the "info" pane you will see a setting for Build Configuration- set that to "debug"
This error is also thrown if you are trying to test your app on a device with a distribution profile selected. Make sure you have the correct code-sign settings for development.
You CAN profile the release build on the device. What you have to do is build the release build with a developer certificate. See here.
Instruments basically does its work by becoming the debugger for the app. If you can't run Xcode's debugger against it, then you can't run Instruments against it.
Mostly, entitlements need to be set to allow debugging.
Sometimes after using XCode to debug apps, I find I can't use Instruments until I reboot the device.
Unlike XCode, Instruments can be confused between two apps with the same name, but different bundle IDs. (Or perhaps same name and similar bundle IDs.) When I have multiple versions of an app on a device, I often have to delete the extra to get Instruments to connect to the correct app. If you have one debug build and one release build, this could be the problem.
So, delete any duplicates of your app and restart the device. (You could change the display name for release and debug build configurations.)

Resources