无法获取来电的 UUID
Not able to get the UUID of incoming call
我正在使用 callkit 和 pushkit 来实现 voip 呼叫。
要打电话,这是代码
callManager?.startCall(handle: String(format: "%@", "Jane Doe"), video: false)
我也收到了 voip 推送,但是我没有收到接收者的 UUID,有什么办法可以得到它以便可以接听电话。在
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
guard type == .voIP else { return }
print("\(#function) incoming voip notfication: \(payload.dictionaryPayload)")
let uuidString = payload.dictionaryPayload["UUID"] as? String {
let uuid = UUID(uuidString: uuidString)
print(uuid) // this is always nil
let backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
self.displayIncomingCall(uuid: uuid, handle: "Jane Doe"", hasVideo: false) { _ in
UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
}
}
}
我们是否需要向服务器发送一些内容以便它可以在 voip 推送中提供详细信息,请指出我做错了什么。
UUID 可以从 iOS 应用程序本身生成和存储。但是 UUID 对于每个呼叫都应该是唯一的,并且当呼叫结束时,使用与该呼叫相同的 UUID。
用于生成UUID,
NSUUID *callUUID = [NSUUID UUID];
有时这可能是零,使用下面的代码替代,
CFUUIDRef newUniqueID = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef newUniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID);
NSString *uuid = (__bridge NSString *)newUniqueIDString;
CFRelease(newUniqueIDString);
CFRelease(newUniqueID);
注:以上代码写在Objective-C.
我正在使用 callkit 和 pushkit 来实现 voip 呼叫。
要打电话,这是代码
callManager?.startCall(handle: String(format: "%@", "Jane Doe"), video: false)
我也收到了 voip 推送,但是我没有收到接收者的 UUID,有什么办法可以得到它以便可以接听电话。在
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
guard type == .voIP else { return }
print("\(#function) incoming voip notfication: \(payload.dictionaryPayload)")
let uuidString = payload.dictionaryPayload["UUID"] as? String {
let uuid = UUID(uuidString: uuidString)
print(uuid) // this is always nil
let backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
self.displayIncomingCall(uuid: uuid, handle: "Jane Doe"", hasVideo: false) { _ in
UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
}
}
}
我们是否需要向服务器发送一些内容以便它可以在 voip 推送中提供详细信息,请指出我做错了什么。
UUID 可以从 iOS 应用程序本身生成和存储。但是 UUID 对于每个呼叫都应该是唯一的,并且当呼叫结束时,使用与该呼叫相同的 UUID。
用于生成UUID,
NSUUID *callUUID = [NSUUID UUID];
有时这可能是零,使用下面的代码替代,
CFUUIDRef newUniqueID = CFUUIDCreate(kCFAllocatorDefault);
CFStringRef newUniqueIDString = CFUUIDCreateString(kCFAllocatorDefault, newUniqueID);
NSString *uuid = (__bridge NSString *)newUniqueIDString;
CFRelease(newUniqueIDString);
CFRelease(newUniqueID);
注:以上代码写在Objective-C.