App not waking when VOIP received in terminated state

simple :

My issue is, need to show incoming call when the app is in Terminated state !! ⚠️⚠️

Explained :

I am working in a chat application in Flutter for both iOS and Android. It has features like voice and video calling, webRTC is used to enable this feature and everything works fine.

Now I want to enable a new feature when a call is received it should show as a incoming call notification like WhatsApp. To enable this feature, I used flutter_callkit_incoming. But at some point it didn’t work as I expected. I’m using APN service for iOS to receive notification. So I decided to do with VOIP and CXProvider in the iOS side. Apple’s CloudKit push notification console is used to send VOIP notification. It is also working and showing incoming call when a VOIP notification is received and can do function like accepting, reject and end call.

Now, the issue that I’m facing is, when the app is not in the background or terminated, incoming calling notification is not showing. App is softly waking up for a few seconds (app not opened). Log is printing upto some code. In that time I need to redirect to the app with the data received in VOIP notification or it should show incoming calling notification and on accepting it should open app call screen. I couldn’t do with the current code that I implemented.

How to enable with the current code? or Is there any other way to enable this Feature ?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>added this in 'info.plist'
<key>UIBackgroundModes</key>
<array>
<string>voip</string>
<string>audio</string>
<string>fetch</string>
<string>processing</string>
<string>remote-notification</string>
</array>
</code>
<code>added this in 'info.plist' <key>UIBackgroundModes</key> <array> <string>voip</string> <string>audio</string> <string>fetch</string> <string>processing</string> <string>remote-notification</string> </array> </code>
added this in 'info.plist'

<key>UIBackgroundModes</key>
    <array>
        <string>voip</string>
        <string>audio</string>
        <string>fetch</string>
        <string>processing</string>
        <string>remote-notification</string>
    </array>

Flutter side method channel handling

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>platform.setMethodCallHandler(_handleMethod);
Future<void> _handleMethod(MethodCall call) async {
try {
switch (call.method) {
case "onIncomingCall":
final data = Map<String, dynamic>.from(call.arguments);
CallHandler.handleIncomingCall(data['callerId'], data['callType']);
break;
case "onCallAnswered":
CallHandler.handleCallAnswered();
break;
case "onCallDeclined":
CallHandler.handleCallDeclined();
break;
case "notificationClicked":
final Map<String, dynamic> arguments =
call.arguments.runtimeType == String
? jsonDecode(call.arguments)
: call.arguments;
_navigateToMessageScreen(arguments);
break;
case "notificationAccepted":
print("Notification accepted with data: ${call.arguments}");
break;
case "showIncomingCall":
print("Notification accepted with data: ${call.arguments}");
// VoIPHandler.showIncomingCall('callerId', 'callType');
break;
default:
throw MissingPluginException();
}
print('_handle method 5');
} catch (e, trace) {
print('handl method error :: $e');
print(trace);
}
}
</code>
<code>platform.setMethodCallHandler(_handleMethod); Future<void> _handleMethod(MethodCall call) async { try { switch (call.method) { case "onIncomingCall": final data = Map<String, dynamic>.from(call.arguments); CallHandler.handleIncomingCall(data['callerId'], data['callType']); break; case "onCallAnswered": CallHandler.handleCallAnswered(); break; case "onCallDeclined": CallHandler.handleCallDeclined(); break; case "notificationClicked": final Map<String, dynamic> arguments = call.arguments.runtimeType == String ? jsonDecode(call.arguments) : call.arguments; _navigateToMessageScreen(arguments); break; case "notificationAccepted": print("Notification accepted with data: ${call.arguments}"); break; case "showIncomingCall": print("Notification accepted with data: ${call.arguments}"); // VoIPHandler.showIncomingCall('callerId', 'callType'); break; default: throw MissingPluginException(); } print('_handle method 5'); } catch (e, trace) { print('handl method error :: $e'); print(trace); } } </code>
platform.setMethodCallHandler(_handleMethod);

Future<void> _handleMethod(MethodCall call) async {
    try {
      switch (call.method) {
        case "onIncomingCall":
          final data = Map<String, dynamic>.from(call.arguments);
          CallHandler.handleIncomingCall(data['callerId'], data['callType']);
          break;
        case "onCallAnswered":
          CallHandler.handleCallAnswered();
          break;
        case "onCallDeclined":
          CallHandler.handleCallDeclined();
          break;
        case "notificationClicked":
          final Map<String, dynamic> arguments =
              call.arguments.runtimeType == String
                  ? jsonDecode(call.arguments)
                  : call.arguments;
          _navigateToMessageScreen(arguments);
          break;
        case "notificationAccepted":
          print("Notification accepted with data: ${call.arguments}");
          break;
        case "showIncomingCall":
          print("Notification accepted with data: ${call.arguments}");
          // VoIPHandler.showIncomingCall('callerId', 'callType');
          break;
        default:
          throw MissingPluginException();
      }
      print('_handle method 5');
    } catch (e, trace) {
      print('handl method error :: $e');
      print(trace);
    }
  }

AppDelegate.swift – incoming call

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
if type == .voIP {
let token = pushCredentials.token.map { String(format: "%02x", $0) }.joined()
print("VoIP Token: (token)")
voipTokenString = token
}
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
if type == .voIP {
print("Received VoIP Push Payload in terminated state: (payload.dictionaryPayload)")
defaults?.set(payload.dictionaryPayload, forKey: "voipNotificationPayload")
showIncomingCallWithCallKit(callerId: "CallerId", callType: "audio")
completion()
}
}
private func showIncomingCallWithCallKit(callerId: String, callType: String) {
let callUpdate = CXCallUpdate()
callUpdate.remoteHandle = CXHandle(type: .generic, value: callerId)
callUpdate.hasVideo = (callType == "video")
let providerConfiguration = CXProviderConfiguration(localizedName: "Near Chat")
providerConfiguration.supportsVideo = true
providerConfiguration.maximumCallsPerCallGroup = 1
providerConfiguration.supportedHandleTypes = [.generic]
let provider = CXProvider(configuration: providerConfiguration)
provider.setDelegate(self, queue: nil)
provider.reportNewIncomingCall(with: UUID(), update: callUpdate) { error in
if let error = error {
print("Error reporting call: (error.localizedDescription)")
} else {
print("Incoming call successfully reported.")
}
}
}
</code>
<code> func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) { if type == .voIP { let token = pushCredentials.token.map { String(format: "%02x", $0) }.joined() print("VoIP Token: (token)") voipTokenString = token } } func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) { if type == .voIP { print("Received VoIP Push Payload in terminated state: (payload.dictionaryPayload)") defaults?.set(payload.dictionaryPayload, forKey: "voipNotificationPayload") showIncomingCallWithCallKit(callerId: "CallerId", callType: "audio") completion() } } private func showIncomingCallWithCallKit(callerId: String, callType: String) { let callUpdate = CXCallUpdate() callUpdate.remoteHandle = CXHandle(type: .generic, value: callerId) callUpdate.hasVideo = (callType == "video") let providerConfiguration = CXProviderConfiguration(localizedName: "Near Chat") providerConfiguration.supportsVideo = true providerConfiguration.maximumCallsPerCallGroup = 1 providerConfiguration.supportedHandleTypes = [.generic] let provider = CXProvider(configuration: providerConfiguration) provider.setDelegate(self, queue: nil) provider.reportNewIncomingCall(with: UUID(), update: callUpdate) { error in if let error = error { print("Error reporting call: (error.localizedDescription)") } else { print("Incoming call successfully reported.") } } } </code>

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        if type == .voIP {
            let token = pushCredentials.token.map { String(format: "%02x", $0) }.joined()
            print("VoIP Token: (token)")
            voipTokenString = token
        }
    }

    func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
        if type == .voIP {
            print("Received VoIP Push Payload in terminated state: (payload.dictionaryPayload)")
            defaults?.set(payload.dictionaryPayload, forKey: "voipNotificationPayload")
            showIncomingCallWithCallKit(callerId: "CallerId", callType: "audio")
            completion()
        }
    }

private func showIncomingCallWithCallKit(callerId: String, callType: String) {
        let callUpdate = CXCallUpdate()
        callUpdate.remoteHandle = CXHandle(type: .generic, value: callerId)
        callUpdate.hasVideo = (callType == "video")

        let providerConfiguration = CXProviderConfiguration(localizedName: "Near Chat")
        providerConfiguration.supportsVideo = true
        providerConfiguration.maximumCallsPerCallGroup = 1
        providerConfiguration.supportedHandleTypes = [.generic]

        let provider = CXProvider(configuration: providerConfiguration)
        provider.setDelegate(self, queue: nil)

        provider.reportNewIncomingCall(with: UUID(), update: callUpdate) { error in
            if let error = error {
                print("Error reporting call: (error.localizedDescription)")
            } else {
                print("Incoming call successfully reported.")
            }
        }
}


also note that I’m getting log when app is terminated and VOIP received until

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@override
void initState() {
print('splashscreen initstate');
final provider = Provider.of<homePageProvider>(context, listen: false);
</code>
<code>@override void initState() { print('splashscreen initstate'); final provider = Provider.of<homePageProvider>(context, listen: false); </code>
@override
  void initState() {
    print('splashscreen initstate');
    final provider = Provider.of<homePageProvider>(context, listen: false);

Before splash screen, there is only main.dart

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật