forked from mirrors/linphone-iphone
[Clean-up] Code clean-up + speed-up
This commit is contained in:
parent
4bdf3f78f5
commit
f1e6e0c270
9 changed files with 56 additions and 127 deletions
|
|
@ -199,10 +199,10 @@ void assistant_activate_phone_number_link(LinphoneAccountCreator *creator, Linph
|
|||
}
|
||||
[PhoneMainView.instance popToView:DialerView.compositeViewDescription];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneAddressBookUpdate object:NULL];
|
||||
[LinphoneManager.instance.fastAddressBook reloadAllContacts];
|
||||
} else {
|
||||
[thiz showErrorPopup:resp];
|
||||
}
|
||||
[LinphoneManager.instance.fastAddressBook fetchContactsInBackGroundThread];
|
||||
} else {
|
||||
[thiz showErrorPopup:resp];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - other
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
linphone_core_set_default_proxy_config(LC, new_config);
|
||||
// reload address book to prepend proxy config domain to contacts' phone number
|
||||
// todo: STOP doing that!
|
||||
[[LinphoneManager.instance fastAddressBook] reloadAllContacts];
|
||||
[[LinphoneManager.instance fastAddressBook] fetchContactsInBackGroundThread];
|
||||
} else {
|
||||
[self displayAssistantConfigurationError];
|
||||
}
|
||||
|
|
@ -1369,17 +1369,14 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun
|
|||
linphone_core_set_default_proxy_config(LC, config);
|
||||
// reload address book to prepend proxy config domain to contacts' phone number
|
||||
// todo: STOP doing that!
|
||||
[[LinphoneManager.instance fastAddressBook]
|
||||
reloadAllContacts];
|
||||
[PhoneMainView.instance
|
||||
changeCurrentView:
|
||||
DialerView.compositeViewDescription];
|
||||
} else {
|
||||
[self displayAssistantConfigurationError];
|
||||
}
|
||||
} else {
|
||||
[self displayAssistantConfigurationError];
|
||||
}
|
||||
[[LinphoneManager.instance fastAddressBook] fetchContactsInBackGroundThread];
|
||||
[PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription];
|
||||
} else {
|
||||
[self displayAssistantConfigurationError];
|
||||
}
|
||||
} else {
|
||||
[self displayAssistantConfigurationError];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@
|
|||
if (PhoneMainView.instance.currentView == ContactsListView.compositeViewDescription || PhoneMainView.instance.currentView == ContactDetailsView.compositeViewDescription) {
|
||||
[PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription];
|
||||
}
|
||||
[instance.fastAddressBook reloadAllContacts];
|
||||
[instance.fastAddressBook fetchContactsInBackGroundThread];
|
||||
instance.fastAddressBook.needToUpdate = FALSE;
|
||||
const MSList *lists = linphone_core_get_friends_lists(LC);
|
||||
while (lists) {
|
||||
|
|
@ -968,7 +968,7 @@ didInvalidatePushTokenForType:(NSString *)type {
|
|||
linphone_core_set_provisioning_uri(LC, [configURL UTF8String]);
|
||||
[LinphoneManager.instance destroyLinphoneCore];
|
||||
[LinphoneManager.instance startLinphoneCore];
|
||||
[LinphoneManager.instance.fastAddressBook reloadAllContacts];
|
||||
[LinphoneManager.instance.fastAddressBook fetchContactsInBackGroundThread];
|
||||
}
|
||||
|
||||
#pragma mark - Prevent ImagePickerView from rotating
|
||||
|
|
|
|||
|
|
@ -636,7 +636,7 @@
|
|||
}
|
||||
}
|
||||
// reload address book to prepend proxy config domain to contacts' phone number
|
||||
[[LinphoneManager.instance fastAddressBook] reloadAllContacts];
|
||||
[[LinphoneManager.instance fastAddressBook] fetchContactsInBackGroundThread];
|
||||
}
|
||||
|
||||
- (void)synchronizeCodecs:(const MSList *)codecs {
|
||||
|
|
|
|||
|
|
@ -2181,7 +2181,7 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat
|
|||
[self destroyLinphoneCore];
|
||||
[self createLinphoneCore];
|
||||
// reload friends
|
||||
[self.fastAddressBook reloadAllContacts];
|
||||
[self.fastAddressBook fetchContactsInBackGroundThread];
|
||||
|
||||
// reset network state to trigger a new network connectivity assessment
|
||||
linphone_core_set_network_reachable(theLinphoneCore, FALSE);
|
||||
|
|
|
|||
|
|
@ -128,7 +128,6 @@
|
|||
|
||||
- (IBAction)onCallClick:(id)event {
|
||||
LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:_addressLabel.text];
|
||||
LOGE(@"=====>>>> onCallClick() : %@ ", [NSString stringWithUTF8String:linphone_address_as_string(addr)] );
|
||||
[LinphoneManager.instance call:addr];
|
||||
if (addr)
|
||||
linphone_address_destroy(addr);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
@property(readonly, nonatomic) NSMutableDictionary *addressBookMap;
|
||||
@property BOOL needToUpdate;
|
||||
|
||||
- (BOOL)reloadAllContacts;
|
||||
//- (void)saveAddressBook;
|
||||
- (void) fetchContactsInBackGroundThread;
|
||||
- (BOOL)deleteContact:(Contact *)contact;
|
||||
- (BOOL)deleteCNContact:(CNContact *)CNContact;
|
||||
- (BOOL)deleteAllContacts;
|
||||
|
|
|
|||
|
|
@ -192,68 +192,6 @@
|
|||
self.needToUpdate = TRUE;
|
||||
}
|
||||
|
||||
- (BOOL)reloadAllContacts {
|
||||
BOOL success = FALSE;
|
||||
if ([CNContactStore class]) {
|
||||
[_addressBookMap removeAllObjects];
|
||||
// iOS 9 or later
|
||||
NSError *contactError;
|
||||
CNContactStore* store = [[CNContactStore alloc] init];
|
||||
[store
|
||||
containersMatchingPredicate:[CNContainer
|
||||
predicateForContainersWithIdentifiers:@[
|
||||
store.defaultContainerIdentifier
|
||||
]]
|
||||
error:&contactError];
|
||||
NSArray *keysToFetch = @[
|
||||
CNContactEmailAddressesKey, CNContactPhoneNumbersKey,
|
||||
CNContactFamilyNameKey, CNContactGivenNameKey, CNContactNicknameKey,
|
||||
CNContactPostalAddressesKey, CNContactIdentifierKey,
|
||||
CNInstantMessageAddressUsernameKey, CNContactInstantMessageAddressesKey,
|
||||
CNInstantMessageAddressUsernameKey, CNContactImageDataKey
|
||||
];
|
||||
CNContactFetchRequest *request =
|
||||
[[CNContactFetchRequest alloc] initWithKeysToFetch:keysToFetch];
|
||||
|
||||
success =
|
||||
[store enumerateContactsWithFetchRequest:request
|
||||
error:&contactError
|
||||
usingBlock:^(CNContact *__nonnull contact,
|
||||
BOOL *__nonnull stop) {
|
||||
if (contactError) {
|
||||
NSLog(@"error fetching contacts %@",
|
||||
contactError);
|
||||
} else {
|
||||
Contact *newContact = [[Contact alloc]
|
||||
initWithCNContact:contact];
|
||||
[self registerAddrsFor:newContact];
|
||||
}
|
||||
}];
|
||||
// load Linphone friends
|
||||
const MSList *lists = linphone_core_get_friends_lists(LC);
|
||||
while (lists) {
|
||||
LinphoneFriendList *fl = lists->data;
|
||||
const MSList *friends = linphone_friend_list_get_friends(fl);
|
||||
while (friends) {
|
||||
LinphoneFriend *f = friends->data;
|
||||
// only append friends that are not native contacts (already added
|
||||
// above)
|
||||
if (linphone_friend_get_ref_key(f) == NULL) {
|
||||
Contact *contact = [[Contact alloc] initWithFriend:f];
|
||||
[self registerAddrsFor:contact];
|
||||
}
|
||||
friends = friends->next;
|
||||
}
|
||||
linphone_friend_list_update_subscriptions(fl);
|
||||
lists = lists->next;
|
||||
}
|
||||
}
|
||||
[NSNotificationCenter.defaultCenter
|
||||
postNotificationName:kLinphoneAddressBookUpdate
|
||||
object:self];
|
||||
return success;
|
||||
}
|
||||
|
||||
- (void)registerAddrsFor:(Contact *)contact {
|
||||
Contact* mContact = contact;
|
||||
for (NSString *phone in mContact.phones) {
|
||||
|
|
@ -374,44 +312,45 @@
|
|||
}
|
||||
|
||||
- (BOOL)deleteCNContact:(CNContact *)contact {
|
||||
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
|
||||
[saveRequest deleteContact:[contact mutableCopy]];
|
||||
@try {
|
||||
NSLog(@"Success %d", [store executeSaveRequest:saveRequest error:nil]);
|
||||
[self fetchContactsInBackGroundThread];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"description = %@", [exception description]);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
|
||||
[saveRequest deleteContact:[contact mutableCopy]];
|
||||
@try {
|
||||
BOOL success = [store executeSaveRequest:saveRequest error:nil];
|
||||
NSLog(@"Success %d", success);
|
||||
if(success)
|
||||
[self fetchContactsInBackGroundThread];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"description = %@", [exception description]);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
- (BOOL)deleteAllContacts {
|
||||
NSArray *keys = @[ CNContactPhoneNumbersKey ];
|
||||
NSString *containerId = store.defaultContainerIdentifier;
|
||||
NSPredicate *predicate =
|
||||
[CNContact predicateForContactsInContainerWithIdentifier:containerId];
|
||||
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
|
||||
NSError *error;
|
||||
NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate
|
||||
keysToFetch:keys
|
||||
error:&error];
|
||||
if (error) {
|
||||
NSLog(@"error fetching contacts %@", error);
|
||||
return FALSE;
|
||||
} else {
|
||||
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
|
||||
for (CNContact *contact in cnContacts) {
|
||||
[saveRequest deleteContact:[contact mutableCopy]];
|
||||
}
|
||||
@try {
|
||||
NSLog(@"Success %d", [store executeSaveRequest:saveRequest error:nil]);
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"description = %@", [exception description]);
|
||||
return FALSE;
|
||||
}
|
||||
error:&error];
|
||||
if (error) {
|
||||
NSLog(@"error fetching contacts %@", error);
|
||||
return FALSE;
|
||||
} else {
|
||||
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
|
||||
for (CNContact *contact in cnContacts) {
|
||||
[saveRequest deleteContact:[contact mutableCopy]];
|
||||
}
|
||||
@try {
|
||||
NSLog(@"Success %d", [store executeSaveRequest:saveRequest error:nil]);
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"description = %@", [exception description]);
|
||||
return FALSE;
|
||||
}
|
||||
NSLog(@"Deleted contacts %lu", (unsigned long)cnContacts.count);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
- (BOOL)saveContact:(Contact *)contact {
|
||||
|
|
@ -446,14 +385,12 @@
|
|||
}
|
||||
NSError *saveError;
|
||||
@try {
|
||||
NSLog(@"Success %d",
|
||||
[store executeSaveRequest:saveRequest error:&saveError]);
|
||||
[self updateFriend:contact];
|
||||
NSLog(@"Success %d", [store executeSaveRequest:saveRequest error:&saveError]);
|
||||
[self updateFriend:contact];
|
||||
[LinphoneManager.instance setContactsUpdated:TRUE];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"=====>>>>> CNContact SaveRequest failed : description = %@",
|
||||
[exception description]);
|
||||
return FALSE;
|
||||
NSLog(@"=====>>>>> CNContact SaveRequest failed : description = %@", [exception description]);
|
||||
return FALSE;
|
||||
}
|
||||
[self fetchContactsInBackGroundThread];
|
||||
return TRUE;
|
||||
|
|
|
|||
|
|
@ -150,14 +150,11 @@
|
|||
linphone_core_set_file_transfer_server(lc, "https://www.linphone.org:444/lft.php");
|
||||
|
||||
// reload address book to prepend proxy config domain to contacts' phone number
|
||||
[[[LinphoneManager instance] fastAddressBook]
|
||||
reloadAllContacts];
|
||||
[[[LinphoneManager instance] fastAddressBook] fetchContactsInBackGroundThread];
|
||||
|
||||
[self waitForRegistration];
|
||||
[[LinphoneManager instance]
|
||||
lpConfigSetInt:NO
|
||||
forKey:@"animations_preference"];
|
||||
}
|
||||
[self waitForRegistration];
|
||||
[[LinphoneManager instance] lpConfigSetInt:NO forKey:@"animations_preference"];
|
||||
}
|
||||
}
|
||||
|
||||
- (UITableView *)findTableView:(NSString *)table {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue