Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent my app from sending sms to landline numbers

While sending SMS through my app,it should sent it to mobile only but for some contacts when two numbers are there one is landline and other is mobile it sends to landline also.

- (NSMutableArray*)getContactsWithAddressBook:(ABAddressBookRef )addressBook {

contactList = [[NSMutableArray alloc] init];
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for (int i=0;i < nPeople;i++) {
    NSMutableDictionary *dOfPerson=[NSMutableDictionary dictionary];
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);

    //For username and surname
    ABMultiValueRef phones =(__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty));
    CFStringRef firstName, lastName;
    firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty);
    [dOfPerson setObject:[NSString stringWithFormat:@"%@ %@", firstName, lastName] forKey:@"name"];

    //For Email ids
    ABMutableMultiValueRef eMail  = ABRecordCopyValue(ref, kABPersonEmailProperty);
    if(ABMultiValueGetCount(eMail) > 0) {
        [dOfPerson setObject:(__bridge NSString *)ABMultiValueCopyValueAtIndex(eMail, 0) forKey:@"email"];
    }

    NSLog(@"ABMultiValueGetCount(phones)=%ld",ABMultiValueGetCount(phones));
    //For Phone number
    NSString* mobileLabel;
    for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
        mobileLabel = (__bridge NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
        if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
        {
            [dOfPerson setObject:(__bridge NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"];

        }
        else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel])
        {
            [dOfPerson setObject:(__bridge NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"];
            break ;
        }
    }
    [contactList addObject:dOfPerson];
}
return contactList;

}

like image 285
sarita Avatar asked Oct 18 '22 21:10

sarita


1 Answers

There's a beautiful port of Google's Phone number handling library libPhoneNumber for iOS.

It can help you distinguish between fixed line, mobile phone, toll-free, premium numbers and much more. You can add this library to your project using Cocoapods and follow the README for documentation.

Here's the link (iOS Port): https://github.com/iziz/libPhoneNumber-iOS
Google libphonenumber library (For Android): https://github.com/googlei18n/libphonenumber

Both of them carry almost the same functionality and are very accurate in detecting whether the number is valid or not. It saved us a lot of time and money whenever we encountered a phone number incapable of receiving SMS such as that of a landline.

However, as mentioned in the comments as well, most of the fixed line or landline numbers are capable of receiving SMS, in that case, you should ask the user whether they want to have an SMS on specified number or not.

Thank You
Fennec
Happy Coding!

like image 57
tush4r Avatar answered Oct 21 '22 01:10

tush4r