如何从CallKit访问联系人标识符

3

我使用以下代码启动 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,然后在provider中更新调用者的远程名称:

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”作为本地化的呼叫者名称,现在在我的手机最近通话记录中,我看到了一个名为“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”,但联系人标识符为空,我该如何解决?我注意到还有一个名为“customIdentifier”的字段,我可以使用它吗?
谢谢!
1个回答

0

contactIdentifier 是联系人应用中的联系人ID。你设置到 startCallAction.contactIdentifier 中的那个并没有什么意义。要拨打用户电话,您需要使用电话号码、电子邮件或至少姓名。


亚历山大 - 我有一些关于使用CallKit的问题 - 不直接与这个话题相关。有没有一个可以与您联系的好方法? - undefined
好的,但是我差点忘记了它是如何工作的 =) 你可以试试看。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接