add CallKit supported filter for NSE
This commit is contained in:
parent
e664cb8235
commit
9542b0e0f9
|
@ -37,6 +37,20 @@ public class SSKPreferences: NSObject {
|
|||
setBool(newValue, key: areCallsEnabledKey)
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
public static var isCallKitSupported() -> Bool {
|
||||
let userLocale = NSLocale.current
|
||||
|
||||
guard let regionCode = userLocale.regionCode else { return false }
|
||||
|
||||
if regionCode.contains("CN") ||
|
||||
regionCode.contains("CHN") {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
|
|||
}
|
||||
|
||||
private func handleSuccessForIncomingCall(for callMessage: CallMessage, using transaction: YapDatabaseReadWriteTransaction) {
|
||||
if #available(iOSApplicationExtension 14.5, *) {
|
||||
if #available(iOSApplicationExtension 14.5, *), SSKPreferences.isCallKitSupported {
|
||||
if let uuid = callMessage.uuid, let caller = callMessage.sender, let timestamp = callMessage.sentTimestamp {
|
||||
let payload: JSON = ["uuid": uuid, "caller": caller, "timestamp": timestamp]
|
||||
CXProvider.reportNewIncomingVoIPPushPayload(payload) { error in
|
||||
|
@ -239,8 +239,15 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
|
|||
}
|
||||
let identifier = self.request?.identifier ?? UUID().uuidString
|
||||
let request = UNNotificationRequest(identifier: identifier, content: notificationContent, trigger: nil)
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
UNUserNotificationCenter.current().add(request) { error in
|
||||
if let error = error {
|
||||
SNLog("Failed to add notification request due to error:\(error)")
|
||||
}
|
||||
semaphore.signal()
|
||||
}
|
||||
semaphore.wait()
|
||||
SNLog("Add remote notification request")
|
||||
UNUserNotificationCenter.current().add(request)
|
||||
}
|
||||
|
||||
private func handleSuccess(for content: UNMutableNotificationContent) {
|
||||
|
|
Loading…
Reference in New Issue