我正在尝试在收到无声通知时将启动应用程序或传入的呼叫UI。
。目前,我有可行的通知,我可以在收到通知时发送通知并打印出日志
此功能使接收通知:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void){
print("Enitre message (userInfo)")
let state: UIApplication.State = application.applicationState
switch state {
case UIApplication.State.active:
print("State: App is active")
case UIApplication.State.inactive:
print("State: App is inactive")
case UIApplication.State.background:
print("State: App is running in the background")
default:
print("State: Unknown")
}
completionHandler(UIBackgroundFetchResult.newData)
}
是否可以在此功能中打开应用程序或传入呼叫UI?
中的VoIP通知的第一个注册
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
requestPushKit()
return true
}
导入呼叫套件
import CallKit
注册推动套件
fileprivate func requestPushKit() {
let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [.voIP]
}
voip(推套件)的代表
extension AppDelegate: PKPushRegistryDelegate {
func pushRegistry( registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
if type == PKPushType.voIP {
let tokenParts = pushCredentials.token.map { data -> String in
return String(format: "%02.2hhx", data)
}
let tokenString = tokenParts.joined()
print(tokenString)
}
}
func pushRegistry( registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
}
func pushRegistry( registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type:PKPushType, completion: @escaping () -> Void) {
if type == PKPushType.voIP {
self.incomingCall()
}
}
func pushRegistry( registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
if type == PKPushType.voIP {
self.incomingCall()
}
}
}
致电incomingcall方法
fileprivate func defaultConfig() -> CXProviderConfiguration{
let config = CXProviderConfiguration(localizedName: "My App")
config.includesCallsInRecents = true
config.supportsVideo = true
config.maximumCallGroups = 5
config.maximumCallsPerCallGroup = 10
// config.iconTemplateImageData = UIImagePNGRepresentation(UIImage(named: "pizza")!)
// config.ringtoneSound = "ringtone.caf"
return config
}
func incomingCall(){
let provider = CXProvider(configuration: defaultConfig())
provider.setDelegate(self, queue: nil)
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: "Pete Za")
update.hasVideo = true
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
}
并致电套件委托方法
extension AppDelegate : CXProviderDelegate {
func providerDidReset( provider: CXProvider) {
}
func providerDidBegin( provider: CXProvider) {
}
func provider( provider: CXProvider, perform action: CXAnswerCallAction) {
action.fulfill()
}
func provider( provider: CXProvider, perform action: CXEndCallAction) {
action.fulfill()
}
func provider( provider: CXProvider, perform action: CXStartCallAction) {
}
func provider( provider: CXProvider, perform action: CXSetHeldCallAction) {
}
func provider( provider: CXProvider, timedOutPerforming action: CXAction) {
}
func provider( provider: CXProvider, perform action: CXPlayDTMFCallAction) {
}
func provider( provider: CXProvider, perform action: CXSetGroupCallAction) {
}
func provider( provider: CXProvider, perform action: CXSetMutedCallAction) {
}
// func provider(_ provider: CXProvider, execute transaction: CXTransaction) -> Bool {
//
// }
}
如果您需要任何东西,请告诉我们。:)