【问题标题】:How to get the duplicate phone numbers in ABAddressBook MonoTouch如何在 ABAddressBook MonoTouch 中获取重复的电话号码
【发布时间】:2013-02-05 16:05:17
【问题描述】:

我正在开发获取具有相同电话号码的重复联系人的应用程序。 我的问题是常规的 foreach 与大量的联系很慢,我也知道使用谓词可以做到这一点。但我找不到任何带有 monotouch 的示例。

【问题讨论】:

    标签: iphone ios xamarin.ios abaddressbook


    【解决方案1】:

    我不知道 ABAddressBook,但是如果您使用 Xamarin Mobile APi,那么您可以使用如下所示的谓词:

    var abook = new AddressBook();
    abook.RequestPermissions().ContinueWith (t =>
    {
        if (!t.Result)
            return; // Permission denied
    
        var builder = new StringBuilder();
    
        // Full LINQ support
        foreach (Contact c in abook.Where (c => c.FirstName == "Eric" && c.Phones.Any()))
        {
            builder.AppendLine (c.DisplayName);
            foreach (Phone p in c.Phones)
                builder.AppendLine (String.Format ("{0}: {1}", p.Label, p.Number));
    
            builder.AppendLine();
        }
    
        contacts.Text = builder.ToString(); // Update UI
    
    }, TaskScheduler.FromCurrentSynchronizationContext()); // Ensure we're on the UI Thread
    

    来自http://betaapi.xamarin.com/?link=T%3aXamarin.Contacts.AddressBook

    【讨论】:

    • 为了使用这个示例实现我的目标,这将是一个嵌套的 foreach,但性能仍然会很慢.. 如果我想获得重复的电话,我需要循环联系人并获取每个电话然后遍历它们以获取重复项。
    【解决方案2】:

    您可以在 O(N) 时间内完成。此答案使用一个循环来识别数组中的重复项:https://stackoverflow.com/a/12948182/1441667。尝试将 Stuarts 的答案与这种方法结合起来。

    【讨论】:

    • 我不确定如何在我的程序中应用它。你有 c# 示例吗?
    猜你喜欢
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 2018-09-25
    相关资源
    最近更新 更多