Skip to content

Commit e78bf8c

Browse files
Brazolkanat
andauthored
feat(llc): missed push handled on ios (#703)
* missed push handled on ios * fix for ios <14 --------- Co-authored-by: Kanat Kiialbaev <[email protected]>
1 parent 01700c3 commit e78bf8c

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

packages/stream_video_push_notification/ios/Classes/StreamVideoPKDelegateManager.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PushKit
33
import Flutter
44
import flutter_callkit_incoming
55

6-
public class StreamVideoPKDelegateManager: NSObject, PKPushRegistryDelegate {
6+
public class StreamVideoPKDelegateManager: NSObject, PKPushRegistryDelegate, UNUserNotificationCenterDelegate {
77
public static let shared = StreamVideoPKDelegateManager()
88

99
private var pushRegistry: PKPushRegistry?
@@ -15,11 +15,34 @@ public class StreamVideoPKDelegateManager: NSObject, PKPushRegistryDelegate {
1515
}
1616

1717
@objc public func registerForPushNotifications() {
18+
UNUserNotificationCenter.current().delegate = self
19+
UNUserNotificationCenter
20+
.current()
21+
.requestAuthorization(options: [.alert, .sound, .badge]) { granted, _ in
22+
if granted {
23+
DispatchQueue.main.async {
24+
UIApplication.shared.registerForRemoteNotifications()
25+
}
26+
}
27+
}
28+
1829
pushRegistry = PKPushRegistry(queue: DispatchQueue.main)
1930
pushRegistry?.delegate = self
2031
pushRegistry?.desiredPushTypes = [.voIP]
2132
}
2233

34+
public func userNotificationCenter(_ center: UNUserNotificationCenter,
35+
willPresent notification: UNNotification,
36+
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
37+
let payloadDict = notification.request.content
38+
39+
if #available(iOS 14.0, *) {
40+
completionHandler([.list, .banner, .sound])
41+
} else {
42+
completionHandler([.alert])
43+
}
44+
}
45+
2346
public func initChannel(mainChannel: FlutterMethodChannel) {
2447
self.mainChannel = mainChannel
2548
}

packages/stream_video_push_notification/lib/src/stream_video_push_notification.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,27 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
181181
return;
182182
}
183183

184-
void registerDevice(String token) {
184+
void registerDevice(String token, bool isVoIP) {
185185
_client.createDevice(
186186
id: token,
187-
voipToken: pushProvider.isVoIP,
187+
voipToken: isVoIP,
188188
pushProvider: pushProvider.type,
189189
pushProviderName: pushProvider.name,
190190
);
191191
}
192192

193+
if (CurrentPlatform.isIos) {
194+
StreamTokenProvider.getAPNToken().then((token) {
195+
if (token != null) {
196+
registerDevice(token, false);
197+
}
198+
});
199+
}
200+
193201
_subscriptions.addIfAbsent(
194-
_idToken, () => pushProvider.onTokenRefresh.listen(registerDevice));
202+
_idToken,
203+
() => pushProvider.onTokenRefresh
204+
.listen((token) => registerDevice(token, true)));
195205
}
196206

197207
@override
@@ -381,7 +391,7 @@ const _defaultPushParams = StreamVideoPushParams(
381391
audioSessionPreferredSampleRate: 44100.0,
382392
audioSessionPreferredIOBufferDuration: 0.005,
383393
supportsDTMF: true,
384-
supportsHolding: true,
394+
supportsHolding: false,
385395
supportsGrouping: false,
386396
supportsUngrouping: false,
387397
ringtonePath: 'system_ringtone_default',

packages/stream_video_push_notification/lib/src/stream_video_push_provider.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ final class StreamTokenProvider {
7979
}).map((event) => event.body['deviceTokenVoIP']);
8080
}
8181

82+
static Future<String?> getAPNToken() async {
83+
if (!CurrentPlatform.isIos) return null;
84+
85+
final token = await FirebaseMessaging.instance.getAPNSToken();
86+
if (token is! String || token.isEmpty) return null;
87+
88+
return token;
89+
}
90+
8291
/// Gets the current push token for the device.
8392
static Future<String?> getFirebaseToken() async {
8493
final token = await FirebaseMessaging.instance.getToken();

0 commit comments

Comments
 (0)