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

问题描述 投票:3回答:1

我用这段代码启动了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 "作为本地化的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
}

但我得到的结果是:"我只看到 "TestCallName "这个名字。

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",我可以用这个吗?

谢谢

ios swift callkit
1个回答
0
投票

contactIdentifier 是联系人应用中联系人的ID。您设置到 startCallAction.contactIdentifier 意味着什么。要给用户打电话,你需要使用电话或电子邮件,或者至少使用名字。

© www.soinside.com 2019 - 2024. All rights reserved.