首页 文章

从数据库或其他源检索电话号码到AddBlockingEntry

提问于
浏览
0

我是一个如何使用呼叫目录扩展(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方法,我只能设法阻止电话号码 .

Has anyone had any luck retrieving phone numbers from an external source? Database, file or something else?

2 回答

  • 1

    是呼叫目录扩展受到极大的内存限制 . 我的经验是你必须非常保守地分配内存并且非常积极地明确释放内存 .

  • 0

    我一直无法找出原因,但是我的app扩展程序无法从我的sqlite数据库中读取数据,只能写入它 . 我的猜测是,这是因为扩展程序对应用程序的限制比应用程序要严格得多 .

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

    我将我的电话号码列表分成单独的文件,每个文件中包含1000个电话号码 . 它似乎工作 .

相关问题