Giter VIP home page Giter VIP logo

Comments (5)

Ayman-Barghout avatar Ayman-Barghout commented on August 29, 2024

If you have allowed the needed background modes correctly (you can follow this SO answer but also allow VoIP and fetch) and updated AppDelegate.swift to call SwiftCallKeepPlugin.sharedInstance?.displayIncomingCall(data, fromPushKit: true) with correct data then it should work for iOS in the background.

from flutter_callkeep.

kyawthet-wam avatar kyawthet-wam commented on August 29, 2024
In my info.plist -

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

AppDelegate.swift
         
  import UIKit
  import PushKit
  import Flutter
  import flutter_callkeep
  
  @UIApplicationMain
  @objc class AppDelegate: FlutterAppDelegate, PKPushRegistryDelegate {
      override func application(
          _ application: UIApplication,
          didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
      ) -> Bool {
        if #available(iOS 10.0, *) {
    UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
  }
          GeneratedPluginRegistrant.register(with: self)
          
          //Setup VOIP
          let mainQueue = DispatchQueue.main
          let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
          voipRegistry.delegate = self
          voipRegistry.desiredPushTypes = [PKPushType.voIP]
          
          return super.application(application, didFinishLaunchingWithOptions: launchOptions)
      }
      
      // Handle updated push credentials
      func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
          let deviceToken = credentials.token.map { String(format: "%02x", $0) }.joined()
          //Save deviceToken to your server
          SwiftCallKeepPlugin.sharedInstance?.setDevicePushTokenVoIP(deviceToken)
      }
      
      func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
          SwiftCallKeepPlugin.sharedInstance?.setDevicePushTokenVoIP("")
      }
      
      // Handle incoming pushes
      func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: 
        PKPushType, completion: @escaping () -> Void) {
          guard type == .voIP else { return }
          
          let id = payload.dictionaryPayload["id"] as? String ?? ""
          let callerName = payload.dictionaryPayload["callerName"] as? String ?? ""
          let userId = payload.dictionaryPayload["callerId"] as? String ?? ""
          let handle = payload.dictionaryPayload["handle"] as? String ?? ""
          let isVideo = payload.dictionaryPayload["isVideo"] as? Bool ?? false
          let extra = payload.dictionaryPayload["extra"] as? NSDictionary ?? [:]
          let data = flutter_callkeep.Data(id: id, callerName: callerName, handle: handle, hasVideo: isVideo)
          //set more data
          data.extra = extra
          data.appName = "YC Fitness"
          //data.iconName = ...
          //data.....
          SwiftCallKeepPlugin.sharedInstance?.displayIncomingCall(data, fromPushKit: true)
 
      }   
  }

And I have another issue that CallKeep.instance.endAllCalls() does not close the current call screen in ios foreground. Please help me. Thank you for your reply.

from flutter_callkeep.

kyawthet-wam avatar kyawthet-wam commented on August 29, 2024

hello, do you have any idea?

from flutter_callkeep.

Ayman-Barghout avatar Ayman-Barghout commented on August 29, 2024

It'd be hard for me to debug why the background CallKit isn't working for you without more information like which devices you have tried it on and if you set data properly, maybe you can insert swift logs and use MacOS console to debug for yourself and see at which step showing CallKit fails, as for endAllCalls(), this would end the CallKit native call but if you have another call ongoing like Agora or WebRTC you have to specifically listen for the callEnded CallKeepEvent and end the ongoing call yourself.

from flutter_callkeep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.