flutter_callkit_incoming

repository·master·Indexed 42 days ago

https://github.com/hiennguyen92/flutter_callkit_incoming

A Flutter plugin for handling incoming and outgoing call interfaces using Android's custom UI and iOS's CallKit framework. It supports PushKit/VoIP on iOS to wake apps from a terminated state and provides comprehensive call lifecycle management including methods to start, end, and hide calls, as well as listening for call events. Version 3.1.5 supports Swift Package Manager (SPM) for Flutter 3.24+.

Tokens
8.9K
Snippets
24
Records
31
Agent score
53%

What's inside flutter_callkit_incoming

  1. Important iOS requirements for VoIP calls

    master

    When implementing incoming calls on iOS, please note the following critical requirements:

    • Real Device Only: CallKit is not fully supported on the iOS simulator for incoming VoIP calls. You must use a physical device for testing.
    • PushKit Setup: To ensure the app can be woken from a terminated state for incoming VoIP calls, you must set up PushKit.
  2. Configure Android for flutter_callkit_incoming

    master

    To use the plugin on Android, follow these configuration steps:

    1. Update AndroidManifest.xml

    Add the INTERNET permission and set the android:launchMode to singleInstance for your MainActivity.

    2. Add Proguard Rules

    To prevent obfuscation of plugin keys, add the following rule to your proguard-rules.pro file:

    3. Configure MainApplication.kt

    For advanced event handling (like responding to Accept/Decline from native code), you must create a custom MainApplication.kt and register the event callback. You also need to set a manifestPlaceholder in your app-level build.gradle to point to this class.

    <!-- AndroidManifest.xml -->
    <manifest...>
        <uses-permission android:name="android.permission.INTERNET"/>
    
        <application ...>
            <activity ...
                android:name=".MainActivity"
                android:launchMode="singleInstance">
            ...
        </application>
    </manifest>
  3. Install flutter_callkit_incoming

    master

    To use this plugin in your Flutter project, follow these steps:

    1. Install Packages: Add flutter_callkit_incoming to your pubspec.yaml dependencies.
    2. Configure Project: Perform platform-specific configurations for Android and iOS (details in subsequent sections).
    3. Usage: Implement the API to show incoming or outgoing calls.
    dependencies:
      flutter_callkit_incoming: ^3.1.5
  4. Customize iOS Launch Screen Assets

    master

    To change the launch screen image for the iOS version of your app, you can either replace the image files directly in the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory or use Xcode for a more visual approach.

    Using Xcode:

    1. Open your Flutter project's iOS workspace using: open ios/Runner.xcworkspace.
    2. In the Xcode Project Navigator, navigate to Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog to replace the existing ones.
    open ios/Runner.xcworkspace
  5. Configure VoIP Push Notifications in Xcode (Swift)

    master

    After setting up certificates, you must configure your iOS project to handle incoming VoIP pushes.

    • AppDelegate Configuration: You need to implement logic in your AppDelegate.swift to handle the DeviceToken and incoming pushes.
    • Reference Implementation: A complete example of the required AppDelegate.swift configuration can be found in the project's example directory: example/ios/Runner/AppDelegate.swift.

    Ensure your app is configured to handle the lifecycle of a call, including starting calls from recent history if necessary.

  6. Configure iOS for flutter_callkit_incoming

    master

    To use the plugin on iOS, update your Info.plist to include the necessary background modes. If you need to process background tasks, you can also include processing.

    Swift Package Manager (SPM) Support

    For Flutter 3.24+, this plugin supports SPM. To use SPM instead of CocoaPods, run: flutter config --enable-swift-package-manager.

    Note: CocoaPods is in maintenance mode and will become read-only in December 2026; SPM is highly recommended for modern projects.

    <!-- Info.plist -->
    <key>UIBackgroundModes</key>
    <array>
        <string>voip</string>
        <string>remote-notification</string>
        <string>processing</string>
    </array>
  7. Setup PushKit for iOS VoIP applications

    master

    To build a VoIP application that updates in the background and wakes the app when a call is received, you must configure Apple's PushKit. This requires enabling specific capabilities in Xcode and setting up VoIP certificates.

    1. Enable Capabilities and Certificates

    • Bundle ID: Ensure Push Notifications is checked in your Apple Developer Identifier settings.
    • Xcode Capabilities: In your Xcode project, navigate to Capabilities and enable Voice over IP.
    • VoIP Services Certificate:
      1. Generate a VoIP Services Certificate in the Apple Developer Portal.
      2. Download the .cer file and install it into your Keychain Access app.
      3. Export the certificate from Keychain Access as a .p12 file.

    2. Convert Certificate to PEM format

    You must convert your .p12 certificate to a .pem file (named VOIP.pem) to use it with tools like curl for testing.

    openssl pkcs12 -in YOUR_CERTIFICATES.p12 -out VOIP.pem -nodes -clcerts
  8. Test VoIP Push Notifications using Curl

    master

    You can test your VoIP push implementation by sending a manual request to the Apple Push Notification service (APNs) using curl.

    Requirements:

    • A generated VOIP.pem file.
    • The target device token.
    • The correct apns-topic (your app's bundle ID).

    Note for Terminated State Testing: To test how your app behaves when it is in a terminated state, configure your Xcode scheme: Xcode -> Edit Schema -> Wait for the executable to be launched.

    curl -v \
    -d '{"aps":{"alert":"Hien Nguyen Call"},"id":"44d915e1-5ff4-4bed-bf13-c423048ec97a","nameCaller":"Hien Nguyen","handle":"0123456789","isVideo":true}' \
    -H "apns-topic: com.hiennv.testing.voip" \
    -H "apns-push-type: voip" \
    --http2 \
    --cert VOIP.pem:'<passphrase>' \
    https://api.development.push.apple.com/3/device/<device token>
  9. Manage calls (Start, End, Missed, Hide)

    master

    The API provides methods to control the lifecycle of calls:

    • Start Outgoing Call: startCall(params)
    • Show Missed Call Notification: showMissCallNotification(params)
    • Hide Call Notification (Android): hideCallkitIncoming(params)
    • End Specific Call: endCall(uuid)
    • End All Calls: endAllCalls()
    // Start Outgoing Call
    await FlutterCallkitIncoming.startCall(params);
    
    // Show Missed Call
    await FlutterCallkitIncoming.showMissCallNotification(params);
    
    // End specific call
    await FlutterCallkitIncoming.endCall(uuid);
    
    // End all calls
    await FlutterCallkitIncoming.endAllCalls();
  10. Configure Missed Call and Calling Notifications

    master

    You can customize the behavior and text of notifications for both active calls and missed calls.

    Missed Call Notification Configuration

    Used to customize the notification shown when a call times out or is declined.

    • subtitle: Text shown in the notification (Default: Missed Call).
    • callbackText: Text for the action button (Default: Call back).
    • showNotification: Whether to show the notification on timeout (Default: true).
    • isShowCallback: Whether to show the callback action (Default: true).

    Calling Notification Configuration

    Used to customize the notification shown while the phone is ringing.

    • subtitle: Text shown in the notification (Default: Calling...).
    • callbackText: Text for the hang-up action (Default: Hang Up).
    • showNotification: Whether to show the notification (Default: true).
    • isShowCallback: Whether to show the hang-up action (Default: true).