Reputation: 3222
I am writing an app where I need to send all the Address Book contents (namely the names and the numbers) to a server where crossing will be made on them to inform the user which friends from his contacts have this app installed on their device (something similar to most communication apps nowadays). My problem is not in the concept of how to do this, my problem is in the speed and synchronization between the clients and the server.
To retrieve the names and numbers from the Address Book I do a simple loop and store the answers in a NSMutableArray
as follows:
for(CFIndex i=0; i< CFArrayGetCount(peopleMutable); i++)
{
record = CFArrayGetValueAtIndex(peopleMutable, i);
multi = ABRecordCopyValue(record, kABPersonPhoneProperty);
//Contact ID
contactID = (int)ABRecordGetRecordID(record);
//Full Name
fullName = [NSString stringWithFormat:@"%@ %@", (NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty), (NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty)];
int multiCount = ABMultiValueGetCount(multi);
for(CFIndex j=0; j<multiCount; j++)
{
number = (NSString *)ABMultiValueCopyValueAtIndex(multi, j);
[arrayNamesToSend addObject:[NSString stringWithFormat:@"%u;%@;%@;", contactID, fullName, number];];
}
}
Well this loop finishes in around one second (maximum 2 seconds even if you have more than 1000 contact). Lets talk about an average case: on the average one might have 500 names in the Address Book, each name is on the average 15 characters long, and each phone number is on the average 15 characters (in international format), so this leads to a total of 15,000 character to be sent to the server. Based on my modest knowledge in client server programming, it is not recommended to send large amount of bytes in one message from the client to the server, and recommended sizes are between 1024 and 4096 bytes per one message.
Now how do I send these contacts to the server? I thought of:
Any suggestions on how to solve this issue? Is there a way to upload the whole Address Book as one file to the server and then the server will resolve it and does its work? Many thanks in advance.
Upvotes: 3
Views: 1195
Reputation: 185831
This is a REALLY BAD IDEA. You are violating all sorts of privacy concerns by sending address book data to the server. And what's more, you don't need it. What you should do is hash all of the data you care about (using something like SHA1, or perhaps HMAC just to be safe) and send the hashes to the server. You can do your comparisons using the hashes just as well as you can using the raw data, but this way you don't have the serious privacy concerns inherent in sending actual personal data to your server.
In any case, your actual question is about sending a large amount of data to the server. I think your concerns are unjustified. What's wrong with sending all the data as one "message"? It sounds like you only have 15kB or so of data. That's really not that large. If you were sending even a single image to the server you'd go way over that size.
Upvotes: 9