I'm building an app with Ionic 6 + capacitor. It works fine when testing on the browser and the Android build. However, when I try to build it using XCode it just doesn't work: it only shows a blank page.
If I run the command ionic capacitor run ios -l --external from Webstorm, the iphone emulator starts and everything works fine. If I open the project with XCode and click the play button, it shows the emulator with a blank page.
My capacitor.config file is:
{
"appId": "com.ionic.app",
"appName": "ionic-app",
"webDir": "www",
"bundledWebRuntime": false,
}
The console of XCode when starting the app is:
2021-12-30 17:09:09.817042+0100 App[22182:360758] KeyboardPlugin: resize mode - native
⚡️ Loading app at capacitor://localhost...
⚡️ [log] - Angular is running in development mode. Call enableProdMode() to enable production mode.
⚡️ WebView loaded
⚡️ To Native -> App addListener 101717497
Notice that localhost doesn't show the usual 8100 port.
The problem is that when I run the app via XCode, the angular server is not starting, hence the app is only a blank page. If I start the server via ng run app:serve --host=0.0.0.0 --port=8100 and I add the following config to capacitor.config in XCode:
"server": {
"url": "http://localhost:8100"
}
Then everything works fine again.
Is there any command or any capacitor config I would need to include to start the angular server when the app starts? Or I don't need to start it and the problem may be somewhere else?
Thanks in advance
UPDATE:
The problems seems to be in the auth guard. I still have to find out what exactly causing the problem, but without the guard the app works fine.
You can run 2 ways your project:
Live Reload
Built app
Live Reload is a good way for debugging the Mobile App, because you will see the changes in 1 sec.
For Built app, you need to do a lot of process:
Run ng build and check where it's build (usually dist/nameoftheproject)
Go to capacitor config.ts and change "webDir": "www" to webDir: "dist/nameoftheproject"
Remove the server property in capacitor.config.ts (It's only for Live Reload)
Run npx cap sync
Then npx cap open ios for opening Xcode
Now, that's why people prefer using "Live Reload" for debugging because using the "Built app way" it's too long to see every change.
Edit: In fact, when you finish your app, you need to build it again if you plan to publish it on the App Store.
So that's how you will see your app in Xcode. Good luck! <:)
Related
ionic cordova emulate ios -l <target>
Does not work for me. I get an error suggesting that I am targeting the wrong device even though the device I am targeting is listed as a virtual device when running the command:
ionic cordova emulate --list
When I run the app with Xcode instead it works however it does not reload my edits, even if I stop and start the app again.
*** disclaimer: this is both a quick and dirty solution to the aforementioned issues ***
Before running your app in Xcode (pressing the play button), in your project directory run the following command:
ionic cordova prepare ios
This will load your changes and update your app in Xcode before running it in your emulator so you can then debug and see your edits.
Open to suggestions if anyone has a more direct solution!
Try:
cleaning the build folder in Xcode: cmd+shift+k
In the "Device" menu of Simulator, click "Erase All Content and Settings"
Quit Xcode, simulator and whatever program you are running the emulate command in
Reboot the machine
I'm trying to deploy my Ionic app to an iPhone by running either of these commands:
ionic cordova run ios
ionic cordova run ios --device
The console displays the following text:
[OK] Your app has been deployed.
Did you know you can live-reload changes from your app with --livereload?
If we look at the console output everything seems to be fine, but my iPhone doesn't detect anything and the application doesn't run. I managed to get it on my phone by opening the workspace file inside the platforms/ios and running it with Xcode, but that's a pretty tedious process, and I'm sure that's not the way to go, as it doesn't support livereload.
Also, I tried to start a new project and I'm having the same issue, so I guess it's not any plugin's fault.
Thanks in advance for your answers.
When you run the app from Xcode, does Xcode give you any more error messages in its output window? This may be a signing issue.
same error here from console.
with --verbose
get this message
registerShutdownFunction.process.exit/normal shutdown
When I run cordova run ios --emulator the script exits successfully and tells me, that there's a file (console.log) inside platforms/ios/cordova but there's no such file although I used console.log several times in my code.
Also, Safari does not show my device in the developer menu when it's connected via USB and running the app. I used cordova run ios --device to run the app.
Am I looking in the wrong place? Does the script lie? :D
I'm struggling to get my code working with react-native run-ios. The native code is pulling some old cached version of the javascript bundle, and I can't seem to clear that to save my life.
When I run the application from XCode however, the application runs just fine. Awesome!
The only problem is that when I run my application through XCode, I can't seem to access the javascript logs. I've tried react-native log-ios but that doesn't seem to show my logs. I've tried "Enabling debugging in Chrome" from the simulator menu, but this option isn't available to me when I run the app from XCode.
Does anybody have any thoughts on what might be going on here?
Option #1
console.log works. By default on iOS, it logs to the debug pane inside Xcode. If you select the "Debug in Chrome" or "Debug in Safari" options from the rage shake menu (⌘+^+Z), it will log to the browser's console instead.
Option #2
As of React Native 0.29 you'll be able to simply run the following to see logs on the command line:
react-native log-ios
react-native log-android
Option #3
cmd ⌘ + D to bring up the debug menu
Set "Debug in Safari" turned off, and some messages would be printed to the output message, but not console messages. However, one of the log message says:
DEV === false, development-level warning are OFF, performance optimizations are ON"
This was because I had previously bundled my project for testing on a real device with the command:
react-native bundle --minify
This bundled without "dev-mode" on. To allow dev messages, include the --dev flag:
react-native bundle --dev
And console.log messages are back! If you aren't bundling for a real device, don't forget to re-point jsCodeLocation in AppDelegate.m to localhost (I did!).
It seems that react-native log-ios is not working anymore since RN .50
You can use react-native-log-ios npm package instead
npm i -g react-native-log-ios
and then
react-native-log-ios <XCode Project Name>
If you close the app on the device (so that XCode shows it as stopped) and then start the app again (through the device, not with XCode), the console logs will go to the terminal (assuming metro is running).
Of course, you don't get XCode debug logs, for my needs that's fine.
react native can't run iOS,I have to configure the environment in accordance with the official website of the method, but has been unable to run
first
Run time results
Try this:
Shut the Terminal spawned by React Native.
Shut down XCode completely
Re-open everything and re-run.
Try:
Close the terminal packer
Stop Xcode from debugging
Close the Google Chrome tab that has been spawned for debugging purposes
Restart Xcode debugging using the Play button
OR
By navigating to your React Native project folder, run:
npm start