【问题标题】:Retrieving phone numbers from database or other source to AddBlockingEntry从数据库或其他来源检索电话号码到 AddBlockingEntry
【发布时间】:2016-11-12 22:15:23
【问题描述】:

我正在关注 Xamarin 的示例,了解如何使用呼叫目录扩展 (full example here) 在 iOS 10 应用中阻止电话号码。

以下是我添加要阻止的电话号码的代码(基于 Xamarin 的示例):

bool AddBlockingPhoneNumbers(CXCallDirectoryExtensionContext context)
{
    // This logging works, log written to database.
    _logService.Log("Start adding numbers");

    // Hardcoding phone numbers to add works.
    var phones = new List<Phone> { 
        new Phone { 
            PhoneNumber = 14085555555, 
            CompanyName = "Bjarte" } 
    };

    // When I uncomment the following line, the 
    // extension crashes here, I never get to the
    // logging below.
    //List<Phone> phones = _phoneService.GetPhones();

    foreach (var phone in phones)
    {
        context.AddBlockingEntry(phone.PhoneNumber);
    }

    _logService.Log("Finished adding numbers");
    return true;
}

为了在应用程序和扩展程序之间进行通信,我设置了一个具有共享目录的应用程序组。这里我有一个 SQLite 数据库,应用程序和扩展程序都可以成功写入。例如,我用它来记录日志,因为我不能直接调试扩展。

在这个数据库中,我有想要屏蔽的电话号码。

这是我从数据库中检索电话号码的方法。我正在使用 NuGet 包 sqlite-net

public List<Phone> GetPhones()
{
    var phones = new List<Phone>();

    using (var db = new SQLiteConnection(DbHelper.DbPath()))
    {
        var phoneTable = db.Table<Phone>().OrderBy(x => x.PhoneNumber);
        foreach (var phone in phoneTable)
        {
            phones.Add(new Phone
            {
                PhoneNumber = phone.PhoneNumber,
                CompanyName = phone.CompanyName
            });
        }
    }

    return phones;
}

到目前为止,如果我将电话号码硬编码到 AddBlockingPhoneNumbers 方法,我只能设法阻止它们。

有没有人成功地从外部来源检索电话号码?数据库、文件还是其他东西?

【问题讨论】:

    标签: c# xamarin ios10 callkit


    【解决方案1】:

    是的,呼叫目录扩展非常受内存限制。我的经验是,你必须非常保守地分配内存,并且在显式释放它时非常积极。

    【讨论】:

      【解决方案2】:

      我无法弄清楚原因,但我的应用程序扩展无法从我的 sqlite 数据库中读取数据,只能写入它。我的疯狂猜测是,这是因为扩展程序对其允许执行的操作有比应用程序更严格的限制。

      但是,如果我用纯文本文件替换数据库,只要文件足够小,它就可以工作。

      我将电话号码列表分成单独的文件,每个文件包含 1000 个电话号码。它似乎有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-24
        • 2012-05-03
        • 2010-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多