capacitor-background-runner icon indicating copy to clipboard operation
capacitor-background-runner copied to clipboard

Fetch problem on iOS 17 simulator

Open petrot opened this issue 2 years ago • 1 comments

I got the following error on iOS simulator:

CapacitorBackgroundRunner/BackgroundRunner.swift:160: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

The problematic code is this:

returnObj.toDictionary().forEach { key, value in. // Line 160
   dict[String(describing: key)] = value
}

My code in the runner.js file:

addEventListener("fetchTest", async (resolve, reject, args) => {
  try {
    const res = await fetch("https://randomuser.me/api/");
    console.log("res???", res);

    resolve('plain text');
  } catch (err) {
    console.error(err);
    reject(err);
  }
});

petrot avatar Nov 14 '23 14:11 petrot

Hi @petrot , I found the same issue. The quick solution is to put the resolve() value as an object.

addEventListener("fetchTest", async (resolve, reject, args) => {
  try {
    const res = await fetch("https://randomuser.me/api/");
    console.log("res???", res);

    resolve({
     text: 'plain text'
     });
  } catch (err) {
    console.error(err);
    reject(err);
  }
});

jethro91 avatar Dec 14 '24 04:12 jethro91