1

I just build a video call app in flutter for android and ios,

I used callkeep to show incoming call notification and fcm push notification. In ios it works when the app is in foreground. but it is not showing when the app is in background.

In android it works both in foreground and background.

How to fix this issue?

Panther
  • 29
  • 4

2 Answers2

0

you should use this package for your case flutter_ios_voip_kit, this is the link: https://pub.dev/packages/flutter_ios_voip_kit

alaa
  • 93
  • 1
  • 6
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33043291) – mrgnhnt96 Nov 02 '22 at 21:57
0

For us the only reliable way to be "called" on iOS was using VoIP. You can use this also with callkeep. However you will need to call the APN not via firebase, but have to implement the call yourself.

In our case this looks like below. And there are several good tutorials on this. For example here: https://levelup.gitconnected.com/send-push-notification-through-apns-using-node-js-7427a01662a2

const key = fs.readFileSync(__dirname + "/AuthKey_XXXXXXXXXX.p8", 'utf8');

//"iat" should not be older than 1 hr from current time or will get rejected
const token = jwt.sign(
    {
        iss: "XXXXXXXXX", //"team ID" of your developer account
        iat: Math.floor(new Date().getTime() / 1000)
    },
    key,
    {
        header: {
            alg: "ES256",
            kid: "XXXXXXXXXXX", //issuer key which is "key ID" of your p8 file
        }
    }
);
const options = {
      ':method': 'POST',
      ':scheme': 'https',
      ':path': '/3/device/' + deviceToken,
      'apns-topic': 'XXX.ANEXAMPLE.ID.voip',//VERY IMPORTANT TO ADD THE .voip here
      'apns-push-type': 'voip',
      'apns-priority': '10',
      'apns-expiration': '0',
      'authorization': `bearer ${token}`
};

const uuid = crypto.randomUUID()

fullName = change.data().firstName + ' ' + change.data().lastName;
body = {
    uuid: uuid,
    caller_id: context.params.callerId,
    caller_name: context.params.callerId,
    has_video: true,
    caller_id_type: "number"
};
strBody = JSON.stringify(body);

console.log("BODY: " + strBody);

let data = '';
const client = http2.connect('https://api.push.apple.com');
buff = Buffer.from(strBody);
req = client.request(options);
req.write(buff);
req.on('response', (headers) => {
      for (const name in headers) {
        console.log(`${name}: ${headers[name]}`)
      }
    })
    .on('data', (chunk) => { data += chunk })
    .on('end', () => {
      console.log(`\n${data}`)
      client.close()
    })
    .on('error', (err) => console.error(err));
req.end();
jan
  • 453
  • 3
  • 13