react-native iOS app not showing static assets (images) after deploying

前端 未结 5 1548
-上瘾入骨i
-上瘾入骨i 2020-12-01 12:58

I have all my static images in a folder called \"images\" in the root of my project. However, after I run the following command to bundle my app, the app works but no image

相关标签:
5条回答
  • 2020-12-01 13:11

    The asset destination and the main.jsbundle have to be in the same folder. Try:

    ./react-native bundle --minify --entry-file index.ios.js --platform ios --dev false --bundle-output ./release/main.jsbundle --assets-dest ./release
    

    The bundler will create an assets folder in there anyway.

    UPDATE including information from the discussions below:

    The react-native-xcode.sh script that is executed in a XCode build step copies the main.jsbundle and the assets folder created by the bundler into the app package. If you want to deploy the package manually you need to make sure, that those files are copied. The easiest way is to include the main.jsbundle directly into the project and create a folder link to the assets folder. Verify that both are showing up in 'Build Phases' -> 'Copy Bundle Resources'.

    0 讨论(0)
  • 2020-12-01 13:16

    For a newer version of react-native use the following:

    react-native bundle --minify --entry-file index.js --platform ios --dev false --bundle-output ./ios/main.jsbundle --assets-dest ./ios
    

    You will see asset folder and main.jsbundle file in the ios folder. After that go to Xcode -> build phases -> copy bundle resources and then add the asset folder and main.jsbundle file. Don't forget to click on the Copy if needed

    0 讨论(0)
  • 2020-12-01 13:29

    Local assets do not load even if you are working on a newer Xcode versions i.e. 12.x or later. There are two solutions to it :

    1. Upgrade react-native versions
    2. Or go to below file:
    node_modules > react-native > Libraries > Images > RCTUIImageViewAnimated.m search for `if (_currentFrame)`
    

    add the following else block to the if block as below

    if (_currentFrame) {
      layer.contentsScale = self.animatedImageScale;
      layer.contents = (__bridge id)_currentFrame.CGImage;
     } else {
      [super displayLayer:layer];
     }
    

    If its older xcode you need to add assets and main.jsbundle under Xcode -> build phases -> copy bundle resources

    0 讨论(0)
  • 2020-12-01 13:31

    Please check XCode console log first. You will find that the app couldn't find out those specific image assets on path "{project name}.app/assets/resources/.."

    So, you need to put images on those fixed paths, unlike iOS native App. Lets add "assets" folder to your 'Copy Bundle Resources'.

    Step 1: Select XCode project -> Build Phases -> Copy Bundle Resources

    Step 2

    Step 3

    Step 4

    0 讨论(0)
  • 2020-12-01 13:31

    I fixed that problem changing my xcode version from 9.3 to 9.2

    0 讨论(0)
提交回复
热议问题