【发布时间】:2018-02-08 08:40:21
【问题描述】:
我正在尝试在我的 VoIP 应用程序中实现 Apple CallKit。我正在使用 Xcode 9.2、Swift 4.0.3、iOS 10.3。问题是我不知道该怎么做。我曾尝试在网络上搜索教程,但我未能找到基于真实系统的教程。他们都使用假系统,只模拟呼叫!我有一个类,它与负责调用的第三方库一起规则。所以,如果我有来电发生,一些事件会通过观察者。像这样:
NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: Notifications.Name.transMessage.rawValue), object: nil, queue: nil) { notification in
self.handleLibtransEvents()
}
其中 self.handleLibtransEvents 是私有函数调用。 另外,我在 AppDelegate.swift 中安装了有效的 PUSH 通知系统。像这样:
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("NOTIFICATION ERROR: \(error)")
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let pushToken = deviceToken.reduce("", {$0 + String(format: "%02X", $1)}).lowercased()
print("pushToken: \(pushToken)")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if UIApplication.shared.applicationState != UIApplicationState.active {
// PUSH: Incoming call event!
}
}
所以有两个地方,我可以接听来电,但我不知道如何通过 Apple CallKit 接听真正的电话。我将感谢任何帮助、建议、电话示例。谢谢! P.S. 我已经正确安装了所有设置。
【问题讨论】:
-
callkit 演示在 github 上可用,下载代码并在设备上运行以了解功能。
标签: swift apple-push-notifications push voip callkit