3

I have created one application the same as WhatsApp to chat with the same industry people and my basic concept is to sync user contact and find a user who is using this app and users can chat with each other.

Contact sync I have done in my application and its working fine till 100 to 500 contacts but if any user has 2000 to 3000 contacts in his contact book its taking time to sync with the server.

I am using the below code to get user contacts and sent them to the server.

ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
NSMutableArray *contacListAddIntoDatabase = [NSMutableArray new];

for (id record in allContacts) {
    ABRecordRef thisContact = (__bridge ABRecordRef)record;
    //save Contact in DataBase.
}

After saving all records in the local database i am sending that record to the server to check if that contact is a user of my app and get backlist of users who are using my app. I have implemented paging in contactsync service.

Here is my contact sync to server code :

if ([[APP_DELEGATE contactArrayForSync] count] > 0) {
    int long pageSize = ([[APP_DELEGATE contactArrayForSync] count] > CONTACT_SYNC_PAGE_SIZE ) ? CONTACT_SYNC_PAGE_SIZE : [[APP_DELEGATE contactArrayForSync] count];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:contactList
                                            options:0
                                            error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    [[APP_DELEGATE apiManager] syncUserContacts:[APP_DELEGATE getEncryptedUserID] andJSONString:jsonString withCallback:^(BOOL success, id responseObject) {
        //Update DataBase as per server response
    }];
}

to sync 2000 contacts it's taking around 2min to sync and its very large amount of time to sync contacts.

I want to reduce this time so is there any way to get sync data in sorter time.

I am stuck here and the client asking a faster solution to sync my contacts.

Note: In the server, I have around 50000 records in my Contact table and it may increase in the future.

any suggestions will be appreciated.

UPDATE: At the first time I am sending all contacts to a server in paging that's fine but after first sync every second sync I need to send only updated or newly added records right now I am sending all record to the server every time.

so how can I get an updated record or newly added record and faster next time sync also?

CodeChanger
  • 7,953
  • 5
  • 49
  • 80

2 Answers2

1

I think you can speed up the syncing by changing some implementation to your code as well on server side code. you send all phone numbers in on array of dictionary (name, all phone number comma separated) you need to create this structure while you are fetching the records from address book, now change your logic accordingly on the server side. both of your task storing in database and syncing can be done on different threads.

Hope this helps for you.

Bhupesh
  • 2,310
  • 13
  • 33
  • Bhupesh, I have already send all phone numbers with array of dictionary and get optimize response from server. is there any other way to sync my contact faster ? – CodeChanger Aug 17 '16 at 08:29
  • but how you are fetching multiple numbers for single user ?? there is where we can optimize code little bit. – Bhupesh Aug 17 '16 at 08:41
  • No dear i want just single number of saved contact and this is not place where my syncing is taking time. My real problem is when user want to update sync with his updated contacts agin at that time its taking same time as first syncing so I want to reduce update contact syncing. – CodeChanger Aug 17 '16 at 08:45
  • can you compress your data like g-zip,etc while sending to server ? may be by this way you can do it.. – Bhupesh Aug 17 '16 at 09:08
  • g-zip algo already implemented at server side and as there is very small response so may be it wont much affect on process! – CodeChanger Aug 17 '16 at 09:22
  • but that same thing you need to implement at your end too, this is what I want to say – Bhupesh Aug 17 '16 at 09:32
  • Bhupesh, I don't know how to add gzip at iOS side can you please guide me on this ? – CodeChanger Aug 22 '16 at 04:32
  • Please check this link, may be this will help you.. http://stackoverflow.com/questions/230984/compression-api-on-the-iphone http://stackoverflow.com/questions/10270203/how-to-gzip-nsdata-with-zlib – Bhupesh Aug 22 '16 at 11:46
0

You can use realm for local storage with observe function. Then you can listen changes from realm for remote sync.