iOS not updated on build

I am not sure if this is a capacitor question or Xcode question. In localhost on web, I am seeing all the updated UI. When I build for mobile purposes, I do not see any changes.

Following:

  • ionic build
  • npx cap copy ios (also tried npx cap sync iOS)
  • npx cap open ios

When I look at the public folder under iOS app/public to search my update, I can see the changes in main.js file.
Yes, I cleared build folder under product. I also restarted Xcode. I also removed app on physical device and also tried on different simulators. Nothing changed.

Xcode version: 12.4
ionic 6.12.4

getting a bit frustrated with this, has been weeks.
So I just tried going into the iOS folder and do pod install, it worked the first time around. (Also surprised why cap sync didn’t “install”) After the following build, it reverted back to old version on next sync.

1 Like

in case anyone runs into this trouble.
You need to delete the iOS folder and restart everything, it seems. This isn’t great though since all the configuration I had under iOS gets removed. So do keep a copy/reference of your old files.

Hmm this doesn’t seem right…I can’t replicate this on my end with a testing project.

  • ionic start my-app tabs
  • ionic build
  • ionic cap add ios
  • ionic cap sync ios

Then run/build the project

I make a change to anything in my typescript…

  • ionic build
  • ionic cap sync ios

and the code is updated in xcode/device/sim.

Am i missing anything?

1 Like

Thanks. You are correct and that’s also what I was doing too but nothing changed. (This started happening recently.)
I honestly cannot figure out why it wasn’t updating. Deleting the folder and restarting all over was my last resort.

Can you share some more information? ionic info?

What’s your capacitor version?

I’m seeing the same thing happen with my current setup. I would rather not delete my iOS folder and restart this so I was wondering if you figured out where some files may be cached.

It’s like the JavaScript files are not being updated on new native builds to the device.

Once you deleted the iOS folder did your builds work correctly going forward?

1 Like

Currently facing the exact same problem, have done all of the mentioned methods above except deleted IOS folder, hoping to get a solution.

You can also try to delete DeriviedData, in case your app is cached with XCode for some reason. It can just randomly happen sometimes!

Did we found a solution here?

close your editor(s) clean all build folders (no need to delete anything) and then build again (in vscode in my case) and ionic cap sync again. Worked for me

This still isn’t working for me…here’s my ionic info output

Ionic:

   Ionic CLI       : 7.2.0 (/Users/esro/.nvm/versions/node/v18.18.2/lib/node_modules/@ionic/cli)
   Ionic Framework : @ionic/vue 7.6.1

Capacitor:

   Capacitor CLI      : 5.6.0
   @capacitor/android : not installed
   @capacitor/core    : 5.6.0
   @capacitor/ios     : 5.6.0

Utility:

   cordova-res                          : not installed globally
   native-run (update available: 2.0.1) : 2.0.0

System:

   NodeJS : v18.18.2 (/Users/esro/.nvm/versions/node/v18.18.2/bin/node)
   npm    : 9.8.1
   OS     : macOS Unknown

This is happening for me, and deleting the ios folder and clearing all build folders isn’t working. The javascript build folder has the latest code which I confirmed by running it using a local web server, but the ios build is always an older version.

Try Clean/Rebuild and Removing Derived Data - iOS Troubleshooting Guide | Capacitor Documentation

For me the way I built the app was crucial. As Josh Morony pointed out here.

If you update something in the code after that you have run the app via XCode on your phone or the simulator, and you want to see the change, you have to build first:

Using Ionic CLI:
ionic build

Using Vite:
npm run build
(npx cap build ios did not work for me)

Then:
ion cap copy ios
ion cap run ios

1 Like

Same issue here. I can’t find absolutely no way to make the native app reflect latest code changes in the PWA.
I updated the version number of my MainPage.js and in xCode, if I search in App/App/public/static/js/main.something.js I can find it there. However, the code of the native App didn’t change after build (I also added a simple “hello” to a text field).
Struggling with this for hours now I already did (some steps multiple times):
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Caches/com.apple.dt.Xcode
rm -rf ~/Library/Developer/Xcode/UserData
I reset the simulator
I did “Clean build folder” in xCode
I removed the full ios folder in my app folder - and I checked by doing npx cap open ios and receiving an error
then:
npm run build
npx cap add ios
npx cap open ios

And I am back to where I started. In fact I can see it right away because if behaves like running in a browser, so this:
const isIosNative = deviceInfo ? (deviceInfo.device === ‘iPhone’ && deviceInfo.engine === ‘WebKit’ && deviceInfo.browser?.startsWith(“WebKit”)) : false;
doesn’t become true, because I added this code after building the native app for the very first time.
But also my “hello” doesn’t show up.

I even thought xCode might do something stupid and checks if the code I try to run got committed. Created a branch, commited code there, xCode sees the new branch, nothing changed…

What am I doing wrong here? What else can I do?

Ok, for all others running into the same issue:

If you configure server: {} in capacitor.config.json and provide the url key pointing to your dev environment there, the native app will do nothing with the code you generated running npm run build or similar. It will copy it into your xCode project and it will sit there. But it doesn’t work like one would expect it - like a replacement for the service-worker cache. It just doesn’t do anything with it. It will use whatever is in the public folder and from there directly talk to the url configured in the value of server.url key.
Now, if you started the implementation of capacitor on a new branch of your existing web-app (because you wanted to make sure not to break the web-app), did code changes there, etc. your web-app test env will most likely still serve the code of your main branch - so the native app will show the main branch, no matter how many nice and fancy things you added locally to your web-app code to improve the native app.

I found this out checking the nginx access logs of my dev environment.

So I guess this may bite anyone already having a proper dev env running and using relative path inside the app (fetch /api/my-endpoint).
E.g. my API runs under the same domain name that also serves out the web-app (e.g. https://myapp.test and https://myapp.test/api - not https://api.myapp.test). To make the native app find my api I configured https://myapp.test as the url. Unfortunately also the views and everything get loaded via this URL then, main.js bundled inside the native app package will get ignored.

Fix:
Create an env variable to configure the base_url and added it to all API calls (no relative any longer).
Remove url key from server object in capacitor.config.json.

So I tried everything mentioned above that didn’t work, but one thing we missed was
npm run build

p.s.
I still deleted android/ios folder and then run npm run build and then other commands of npx add android/ios and npx cap sync

This solved the problem for me

1 Like

running ‘npm run build’ and then teh otehr two ‘npx cap …’ commands worked for me. Thank you!