luowei / LWContactManager

LWContactManager,通讯录管理,基于APAddressBook封装,简化了授权逻辑,获取联系人列表按中文拼音排序。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LWContactManager

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

-(LWAddressBookService *)addressBookService{
    if(!_addressBookService){
        _addressBookService = [[LWAddressBookService alloc] init];
    }
    return _addressBookService;
}

//联系人列表
- (void)reloadSearchAddressBook {
    __weak typeof(self) weakSelf = self;
    [self.addressBookService requestAccess:^(BOOL granted, NSError *error) {
        __strong typeof(self) strongSelf = weakSelf;
        if (granted) {
            NSString *searchText = [strongSelf searchText];
            [strongSelf.addressBookService
                    loadContactsWithSearchText:searchText
                                  successBlock:^(NSArray<APContact *> *contacts, NSError *err) {
                                      [strongSelf setContacts:contacts];
                                      [strongSelf reloadData];
                                      [strongSelf.collectionViewLayout invalidateLayout];
                                  }];
        }
    }];
}

Requirements

Installation

LWContactManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'LWContactManager'

Carthage

github "luowei/LWContactManager"

Usage


-(LWAddressBookService *)addressBookService{
    if(!_addressBookService){
        _addressBookService = [[LWAddressBookService alloc] init];
    }
    return _addressBookService;
}

//重新搜索联系人列表
- (void)reloadSearchAddressBook {
    __weak typeof(self) weakSelf = self;
    [self.addressBookService requestAccess:^(BOOL granted, NSError *error) {
        __strong typeof(self) strongSelf = weakSelf;
        if (granted) {
            NSString *searchText = [strongSelf searchText];
            [strongSelf.addressBookService
                    loadContactsWithSearchText:searchText
                                  successBlock:^(NSArray<APContact *> *contacts, NSError *err) {
                                        for(APContact *contact in contacts){
                                            NSLog(@"==== name:%@ %@ phone:%@",contact.name.lastName,contact.name.firstName,contact.phones.firstObject.number);
                                        }
                                      //todo:设置联系人
                                  }];
        }
    }];
}

- (NSString *)searchText {
    return @"李";
}

Author

luowei, luowei@wodedata.com

License

LWContactManager is available under the MIT license. See the LICENSE file for more info.

About

LWContactManager,通讯录管理,基于APAddressBook封装,简化了授权逻辑,获取联系人列表按中文拼音排序。

License:MIT License


Languages

Language:Objective-C 88.8%Language:Ruby 5.4%Language:Shell 4.8%Language:C 1.1%