Skip to content

Commit a9a2010

Browse files
authored
fixing background ios callkit call (#557)
1 parent cfdd6f4 commit a9a2010

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

packages/stream_video_push_notification/ios/Classes/StreamVideoPKDelegateManager.swift

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public class StreamVideoPKDelegateManager: NSObject, PKPushRegistryDelegate {
1919
pushRegistry?.delegate = self
2020
pushRegistry?.desiredPushTypes = [.voIP]
2121
}
22-
22+
2323
public func initChannel(channel: FlutterMethodChannel) {
2424
methodChannel = channel
2525
}
26-
26+
2727
public func initData(data: [String: Any]) {
2828
defaultData = data
2929
}
@@ -43,45 +43,55 @@ public class StreamVideoPKDelegateManager: NSObject, PKPushRegistryDelegate {
4343
guard type == .voIP else {
4444
return completion()
4545
}
46-
46+
47+
var streamDict = payload.dictionaryPayload["stream"] as? [String: Any]
48+
49+
let state = UIApplication.shared.applicationState
50+
if state == .background || state == .inactive {
51+
handleIncomingCall(streamDict: streamDict, state: state, completion: completion)
52+
} else if state == .active {
53+
methodChannel?.invokeMethod("customizeCaller", arguments: streamDict) { (response) in
54+
if let customData = response as? [String: Any] {
55+
streamDict?["created_by_display_name"] = customData["name"] as? String
56+
streamDict?["created_by_id"] = customData["handle"] as? String
57+
}
58+
59+
self.handleIncomingCall(streamDict: streamDict, state: state, completion: completion)
60+
}
61+
}
62+
}
63+
64+
func handleIncomingCall(streamDict: [String: Any]?, state: UIApplication.State, completion: @escaping () -> Void) {
4765
let defaultCallText = "Unknown Caller"
48-
49-
// Prepare call kit incoming notification.
50-
let streamDict = payload.dictionaryPayload["stream"] as? [String: Any]
66+
5167
let callCid = streamDict?["call_cid"] as? String ?? ""
5268
var createdByName = streamDict?["created_by_display_name"] as? String
5369
var createdById = streamDict?["created_by_id"] as? String
54-
55-
methodChannel?.invokeMethod("customizeCaller", arguments: streamDict) { (response) in
56-
if let customData = response as? [String: Any] {
57-
createdByName = customData["name"] as? String ?? createdByName
58-
createdById = customData["handle"] as? String ?? createdById
59-
}
60-
61-
let data: StreamVideoPushParams
62-
if let jsonData = self.defaultData {
63-
data = StreamVideoPushParams(args: jsonData)
64-
} else {
65-
data = StreamVideoPushParams(args: [String: Any]())
66-
}
67-
68-
data.callKitData.uuid = UUID().uuidString
69-
data.callKitData.nameCaller = createdByName ?? defaultCallText
70-
data.callKitData.handle = createdById ?? defaultCallText
71-
data.callKitData.type = 1 //video
72-
data.callKitData.extra = ["callCid": callCid]
73-
74-
// Show call incoming notification.
75-
StreamVideoPushNotificationPlugin.showIncomingCall(
76-
data: data.callKitData,
77-
fromPushKit: true
78-
)
79-
80-
// Complete after a delay to ensure that the incoming call notification
81-
// is displayed before completing the push notification handling.
82-
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
83-
completion()
84-
}
70+
71+
let data: StreamVideoPushParams
72+
if let jsonData = self.defaultData {
73+
data = StreamVideoPushParams(args: jsonData)
74+
} else {
75+
data = StreamVideoPushParams(args: [String: Any]())
76+
}
77+
78+
data.callKitData.uuid = UUID().uuidString
79+
data.callKitData.nameCaller = createdByName ?? defaultCallText
80+
data.callKitData.handle = createdById ?? defaultCallText
81+
data.callKitData.type = 1 //video
82+
data.callKitData.extra = ["callCid": callCid]
83+
84+
// Show call incoming notification.
85+
StreamVideoPushNotificationPlugin.showIncomingCall(
86+
data: data.callKitData,
87+
fromPushKit: true
88+
)
89+
90+
// Complete after a delay to ensure that the incoming call notification
91+
// is displayed before completing the push notification handling.
92+
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
93+
completion()
8594
}
8695
}
96+
8797
}

packages/stream_video_push_notification/lib/src/stream_video_push_notification.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const _idCallAcceptDecline = 4;
2020
/// Implementation of [PushNotificationManager] for Stream Video.
2121
class StreamVideoPushNotificationManager implements PushNotificationManager {
2222
/// Factory for creating a new instance of [StreamVideoPushNotificationManager].
23+
/// /// Parameters:
24+
/// * [callerCustomizationCallback] callback providing customized caller data used for call screen and CallKit call. (for iOS this will only work for foreground calls)
2325
static create({
2426
required StreamVideoPushProvider iosPushProvider,
2527
required StreamVideoPushProvider androidPushProvider,

0 commit comments

Comments
 (0)