如何从Callkit访问联系标识符



我使用此代码启动callkit调用:

private func startCallKitCall(call: Call, completion: @escaping (Bool) -> ()){
    let handle              = CXHandle(type: .phoneNumber, value: call.handle)
    let startCallAction     = CXStartCallAction(call: call.uuid, handle: handle)
    startCallAction.isVideo = call.hasVideo
    startCallAction.contactIdentifier = call.uuid.uuidString
    let transaction         = CXTransaction(action: startCallAction)
    requestCallKitTransaction(transaction, completionHandler: { success in
        completion(success)
    })
}

在ContactIdentifier中,我设置了用户UUID,然后在提供商中,更新呼叫者远程名称:

public func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
    let update = CXCallUpdate()
    update.remoteHandle = action.handle
    update.hasVideo = action.isVideo
    update.localizedCallerName = "TestCallName"
    self.provider!.reportCall(with: action.callUUID, updated: update)
    action.fulfill()
}

我使用" testCallName"作为局部callername,现在在最近的电话中,我会看到一行名为" testcallname"的行,如果我单击它,我会在appdelegate上调用此方法:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

    if (userActivity.activityType == "INStartAudioCallIntent"){
        guard let interaction = userActivity.interaction else {
            return false
        }
        var personHandle: INPersonHandle?
        if let startVideoCallIntent = interaction.intent as? INStartVideoCallIntent {
            personHandle = startVideoCallIntent.contacts?[0].personHandle
        } else if let startAudioCallIntent = interaction.intent as? INStartAudioCallIntent {
            personHandle = startAudioCallIntent.contacts?[0].personHandle
            print(startAudioCallIntent.contacts?[0])
        }
        print(personHandle!.value)
    } else if (userActivity.activityType == "INStartVideoCallIntent"){
    } else {
        print("called userActivity: (userActivity.activityType), but not yet supported.")
    }
    return true
}

但是我获得的输出是:

Optional(<INPerson: 0x1742a5280> {
contactIdentifier = "<null>";
customIdentifier = "<null>";
displayName = "<null>";
image = "<null>";
nameComponents = "<null>";
personHandle = "<INPersonHandle: 0x17402f0c0> {n    label = "<null>";n    type = PhoneNumber;n    value = "TestCallName";n}";
relationship = "<null>";
siriMatches = "<null>";
})
 Optional("TestCallName")

我只看到名称" testCallname",但是联系人标识符是" null",我该如何解决?我看到还有一个字段名称" CustomIdentifier",我可以使用吗?

谢谢!

contactIdentifier是联系人应用程序中的联系人的ID。您将其设置在startCallAction.contactIdentifier中的那一无所有。要致电用户,您需要使用电话或电子邮件或至少名称。

相关内容

  • 没有找到相关文章

最新更新