我有电话目录处理程序扩展斯威夫特3 CallKit一个问题
问题描述:
我得到一个错误,当我让我在我的项目中添加扩展名,请告诉我如何解决这个这里是截图Error Image我有电话目录处理程序扩展斯威夫特3 CallKit一个问题
如果您需要任何其他细节,请问我,我会提供他们。
private func addAllBlockingPhoneNumbers(to context: CXCallDirectoryExtensionContext) {
for i in 0...numbers.count - 1
{
let allPhoneNumbers: [CXCallDirectoryPhoneNumber] = [ numbers[i] ]
for phoneNumber in allPhoneNumbers {
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber)
}
}
}
----------------------------
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
context.delegate = self
numbers = DBManager.shared.selectContacts()
}
答
我建议检查错误代码在CXCallDirectoryExtensionContextDelegate
。将此代码放入requestFailed
函数中:
func requestFailed(for extensionContext: CXCallDirectoryExtensionContext, withError error: Error) {
let errorCode = (error as NSError).code
switch errorCode {
case CXErrorCodeCallDirectoryManagerError.Code.unknown.rawValue:
print("Extension could not be load for an unknown reason.")
case CXErrorCodeCallDirectoryManagerError.Code.noExtensionFound.rawValue:
print("Could not load extension. Extension not found")
case CXErrorCodeCallDirectoryManagerError.Code.loadingInterrupted.rawValue:
print("Could not load extension. Extension was interrupted while loading")
case CXErrorCodeCallDirectoryManagerError.Code.entriesOutOfOrder.rawValue:
print("Could not load extension. Call entries are out of order")
case CXErrorCodeCallDirectoryManagerError.Code.duplicateEntries.rawValue:
print("Could not load extension. Duplicate entries")
case CXErrorCodeCallDirectoryManagerError.Code.maximumEntriesExceeded.rawValue:
print("Could not load extension. Maximum entries exceeded")
case CXErrorCodeCallDirectoryManagerError.Code.extensionDisabled.rawValue:
print("Extension not enabled in Settings")
case CXErrorCodeCallDirectoryManagerError.Code.unexpectedIncrementalRemoval.rawValue:
print("Unexpected incremental removal")
case CXErrorCodeCallDirectoryManagerError.Code.currentlyLoading.rawValue:
print("Could not load extension. The extension is currently loading")
default:
print("Could not load extension.")
}
}
现在,在Xcode中调试您的扩展。 (See details here。)当您尝试在设置中启用扩展程序时,Xcode应打印一条错误消息,描述出错的地方。
答
我有这个相同的问题,并能够摆脱这个错误,并成功地链接了电话目录扩展,当我将我的扩展的数据模型添加到目标目录构建阶段。
选择您的项目>选择您的目标扩展>选择Build Phases> +编译源代码。
希望这会有所帮助!
最好看到你的源代码 –
我加了一些代码请检查一下@GabrielLidenor –