iOS: cannot load PNG downloaded and saved with getWritablePath()


I’m using CocosCreator 3.3.2 and I correctly downloaded icon.png from a server.
Then, by using getWritablePath() I correctly saved it into a subfolder I created.
Everything is OK here, I checked iOS simulator and I can see there is a valid file icon.png.

Now I need to load it as a SpriteFrame and display it.
I’m using the command:
resources.load( imgUrl, SpriteFrame, function (err, spriteFrame)
but I’m getting error:
Error: Bundle resources doesn’t contain
(and my correct simulator path)

I also tried to add “/spriteFrame” but no luck.
Any idea?

Everything works fine in case I try to load a local file, for example: “sprites/logo/spriteFrame”.

Many Thanks,

Let me ask engineering to have a look.

You can refer to this code to use:

assetManager.loadRemote<ImageAsset>(filePath, (err, imageAsset)=> {
                    if (err) {
                        console.log("show image error")
                    } else {
                        var newNode = instantiate(this.targetNode);
                        newNode.setPosition(new Vec3(-newNode.position.x, newNode.position.y, newNode.position.z));
                        const spriteFrame = new SpriteFrame();
                        const texture = new Texture2D();
                        texture.image = imageAsset;
                        spriteFrame.texture = texture;
                        newNode.getComponent(Sprite).spriteFrame = spriteFrame;
                        spriteFrame.packable = false;
                        spriteFrame.flipUVY = true;
                        if (sys.isNative && (sys.os === sys.OS.IOS || sys.os === sys.OS.OSX)) {
                            spriteFrame.flipUVY = false;

               = `成功保存在设备目录并加载成功: ${filePath}`;

Thanks, it worked!
Unfortunately I was thinking loadRemote was for remote files only, but it works on local files also :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.