【发布时间】:2017-11-23 13:39:30
【问题描述】:
我正在使用 Callkit 扩展程序来识别号码。我所有的联系人(大约 30k+)都存储在 Realm 中。
我已将 Realm 文件存储在 AppGroup 中,该文件可以在我的应用程序及其扩展程序之间共享。
我在尝试重新加载扩展时收到错误消息。
错误域=com.apple.CallKit.error.calldirectorymanager 代码=7 “(空)”
发生此错误时,我的应用程序的呼叫阻止和识别设置显示一个微调器(而其他应用程序显示切换开关)
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[CXCallDirectoryManager sharedInstance] reloadExtensionWithIdentifier:@"com.j2x.handheldcontact.CallerID" completionHandler:^(NSError *error){
if(error) {
NSLog(@"CallerID - refresh failed. error is %@",[error description]);
}
}];
}
我看到只有当我尝试使用访问应用组目录中的领域时才会发生错误。
在我的扩展子类中:
- (void)beginRequestWithExtensionContext:(CXCallDirectoryExtensionContext *)context
{
context.delegate = self;
NSString *appGroupId = @"group.com.j2x.handheldcontact.CallerID";
NSURL *appGroupDirectoryPath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appGroupId];
NSURL *dataBaseURL = [appGroupDirectoryPath URLByAppendingPathComponent:@"default.realm"];
[[[RLMRealm defaultRealm]configuration]setFileURL:dataBaseURL];
RLMResults *temp = [self getContactArray]; //This gives the callKit error
RLMResults *temp ; //This doesn't give any error
[context completeRequestWithCompletionHandler:nil];
}
-(RLMResults *)getContactArray{
RLMResults *res = [[RealmContact allObjects]objectsWithPredicate:[NSPredicate predicateWithFormat:@"phone <> nil or homePhone <> nil or mobilePhone <> nil or altPhone <> nil or fax <> nil"]];
return res;
}
为什么访问 Realm 数据会出现错误?谓词格式对我来说确实不错。
通过一些研究,我发现了以下代码:
public enum Code : Int {
public typealias _ErrorType = CXErrorCodeCallDirectoryManagerError
case unknown
case noExtensionFound
case loadingInterrupted
case entriesOutOfOrder
case duplicateEntries
case maximumEntriesExceeded
case extensionDisabled
@available(iOS 10.3, *)
case currentlyLoading
@available(iOS 11.0, *)
case unexpectedIncrementalRemoval
}
在我的情况下,错误表示 case currentLoading(代码 7)。我也在只有 250 个联系人的领域上试过这个。但我得到了同样的错误。
编辑:
如果我对联系人进行硬编码,它就可以正常工作。但如果我将 Realm 带入场景,它就会失败。
CXCallDirectoryPhoneNumber phoneNumber = strtoull([@"14xxxxxx86" UTF8String], NULL, 0);
if (phoneNumber > 0) {
[context addIdentificationEntryWithNextSequentialPhoneNumber:phoneNumber label:@"Test Test"];
}
解决方法:
目前,我将所有数据存储到一个文件中,并将该文件保存在应用组中。
NSString *appGroupId = @"group.xxx.CallerID";
NSURL *appGroupDirectoryPath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:appGroupId];
NSURL *appFile = [appGroupDirectoryPath URLByAppendingPathComponent:@"contacts.txt"];
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[appFile path]];
if(exists) {
[[NSFileManager defaultManager]removeItemAtPath:[appFile path] error:nil];
}
[NSKeyedArchiver archiveRootObject:uniqueCallDirectory toFile:[appFile path]];
并在 callID 扩展子类中访问此数组。
【问题讨论】:
-
尝试在您的容器应用中运行相同的代码。
-
@Teja Nandamuri:你解决了这个问题吗?我也收到错误 {Foundation.NSErrorException: Error Domain=com.apple.CallKit.error.calldirectorymanager Code=7 "(null)" 但不知道为什么...我无法在电话设置中启用分机。只是加载图标旋转无穷无尽... thx
标签: ios objective-c realm callkit