【问题标题】:how to find contact's phone number with iOS formatting though Phonegap?如何通过Phonegap查找具有iOS格式的联系人电话号码?
【发布时间】:2015-03-09 15:37:09
【问题描述】:

所以我在尝试使用 Cordova Phonegap 在 IOS 设备上搜索包含区号和/或国家/地区代码的电话号码的联系人时遇到了麻烦。

例如:我与#1 (718) 555-5555 有联系。当我显示该联系人信息时(通过使用contacts.find()的电话间隙),电话号码字符串显示为“1(718)555-5555”。但是如果我尝试使用“1 (718) 555-5555”进行搜索,Phonegap 找不到它。

可以找到没有国家代码和地区代码的数字,例如“555-5555”。

iOS 中包含区号和/或国家/地区代码的电话号码究竟是如何存储的?

function findContact(num) {

if (!navigator.contacts) {
    console.log("Contacts API not supported");
    return;
}

var options = new ContactFindOptions();
options.filter = num;
options.multiple = true;
var fields = ["phoneNumbers"];

navigator.contacts.find(fields, function(contacts) {
                        if (contacts.length == 0) {
                        console.log('Contact not found, num ' + num);
                        }
                        else {
                        console.log('Found ' + contacts.length + ' contacts w/num: ' + num);
                        }
                        }, function(error){}, options);    

}

* 编辑 * 因此,我将问题缩小到了 cordova 联系人插件中的 CDVContact.m。在 testMultiValueStrings 方法中

 valueArray = [self valuesForProperty:propId inRecord:self.record];  

if (valueArray) { 
NSString* valuesAsString = [valueArray componentsJoinedByString:@" "]; 
NSPredicate* containPred = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@", testValue]; 
bFound = [containPred evaluateWithObject:valuesAsString]; } 

valuesAsString 确实以 @"1 (555) 555-5555" 等格式正确显示,并且 testValue 字符串相同,但 bFound 的计算结果仍为 NO。

也许有一些与导致错误的 valueArray 相关的元数据?

【问题讨论】:

    标签: javascript ios cordova


    【解决方案1】:

    所以我发现 iOS 电话号码中的空格是非阻塞空格,即 &nbsp。必须使用 String.fromCharCode(160) 声明搜索字符串中的任何空格。

    【讨论】:

      猜你喜欢
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 2012-06-09
      • 2011-06-11
      相关资源
      最近更新 更多