bool AddBlockingPhoneNumbers(CXCallDirectoryExtensionContext context) { // Retrieve phone numbers to block from data store. For optimal performance and memory usage when there are many phone numbers, // consider only loading a subset of numbers at a given time and using autorelease pool(s) to release objects allocated during each batch of numbers which are loaded. // // Numbers must be provided in numerically ascending order. context.RemoveAllBlockingEntries(); ProfileManager mgr = new ProfileManager(); Profile[] allProfiles = mgr.GetAllProfiles(); List <long> allNumbers = new List <long>(); foreach (Profile prof in allProfiles) { if (!prof.Allowed) { foreach (long phoneNumber in prof.PhoneNumbersAsLongs) { allNumbers.Add(phoneNumber); } } } allNumbers.Sort(); foreach (long phoneNumber in allNumbers) { context.AddBlockingEntry(phoneNumber); } return(true); }
public void RequestFailed(CXCallDirectoryExtensionContext extensionContext, NSError error) { // An error occurred while adding blocking or identification entries, check the NSError for details. // For Call Directory error codes, see the CXErrorCodeCallDirectoryManagerError enum. // // This may be used to store the error details in a location accessible by the extension's containing app, so that the // app may be notified about errors which occured while loading data even if the request to load data was initiated by // the user in Settings instead of via the app itself. }
private bool AddIdentificationPhoneNumbers( CXCallDirectoryExtensionContext context) { var fileIndex = 0; var fileName = GetPhoneFilePath(fileIndex); int entryIndex = 0; // Read all existing files while (File.Exists(fileName)) { //Console.WriteLine($"Extension dictionary {fileIndex}"); // Memory is limited, so flush memory // after each file is read using (new NSAutoreleasePool()) { // The text files have one phone number per line using (StreamReader sr = new StreamReader(fileName)) { while (sr.Peek() >= 0) { var phoneString = (sr.ReadLine()); // Parse string of format // "4722334455;Company name" var delimiterIndex = phoneString.IndexOf(';'); if (delimiterIndex <= -1 || delimiterIndex > phoneString.Length) { continue; } var phoneNumberString = phoneString.Substring(0, delimiterIndex); if (!long.TryParse(phoneNumberString, out long phoneNumber)) { continue; } //Console.WriteLine($"AddIdentificationEntry {entryIndex} {phoneNumber} {phoneString.Substring(delimiterIndex + 1)}"); // Add phone number to the // phone's call directory context.AddIdentificationEntry( phoneNumber, phoneString.Substring(delimiterIndex + 1) ); entryIndex++; } } // Find filename of next file fileName = GetPhoneFilePath(++fileIndex); } } return(true); }
bool AddBlockingPhoneNumbers(CXCallDirectoryExtensionContext context) { // Retrieve phone numbers to block from data store. For optimal performance and memory usage when there are many phone numbers, // consider only loading a subset of numbers at a given time and using autorelease pool(s) to release objects allocated during each batch of numbers which are loaded. // // Numbers must be provided in numerically ascending order. long[] phoneNumbers = { 14085555555, 18005555555 }; foreach (var phoneNumber in phoneNumbers) { context.AddBlockingEntry(phoneNumber); } return(true); }
bool AddIdentificationPhoneNumbers(CXCallDirectoryExtensionContext context) { // Retrieve phone numbers to identify and their identification labels from data store. For optimal performance and memory usage when there are many phone numbers, // consider only loading a subset of numbers at a given time and using autorelease pool(s) to release objects allocated during each batch of numbers which are loaded. // // Numbers must be provided in numerically ascending order. long[] phoneNumbers = { 18775555555, 18885555555 }; string[] labels = { "Telemarketer", "Local business" }; for (var i = 0; i < phoneNumbers.Length; i++) { long phoneNumber = phoneNumbers[i]; string label = labels[i]; context.AddIdentificationEntry(phoneNumber, label); } return(true); }