我正在尝试将所有联系人备份到服务器上。
所以我将联系人转换为vCard字符串并发送 vCard字符串到服务器上,并存储vCard字符串 RecordID进入sqlite数据库
所以第一次用户想要收回所有的 联系人将转到服务器和数据库。
从第二次起,我只想发送新的联系人 服务器。所以我需要比较存储的数据库RecordIds 使用Phonebook RecordIds进入nsarray并获取新内容 RecordIds成一个数组
例如我有40,41,42,43,44,45等RecordIds dbarray。不一定按顺序或顺序。
现在当用户添加5个新联系人时,电话簿阵列将包含 recordIds如40,41,42,43,44,45,46,47,48,50
所以这次我只想发送一条带有recordIds的联系人 46,47,48,49和50.像增量备份这样的东西
我还需要检查是否有任何修改 存储的vCards.So我还需要比较来自的所有vCard字符串 电话簿阵列和数据库阵列。
我是iOS编程的新手,我被困住了。请 救命!!!它迫切需要
答案 0 :(得分:0)
我通过使用以下代码解决了上述问题。希望它可以帮助某人。
-(void)newContactsAndContactsToUpdate
{
NSMutableArray *newContact = [[NSMutableArray alloc]init];
NSMutableArray *newContactRecIds = [[NSMutableArray alloc]init];
NSMutableArray *updateContactRecIds = [[NSMutableArray alloc]init];
NSMutableArray *updateContactRecIds = [[NSMutableArray alloc]init];
//dataArray contains all the contacts(converted into Vcard strings) in the phonebook
//recordIDArray contains the all recordids in the phonebook
//dbArraywithRID contains the recordids stored in database.
//dbArraywithVcard contains contacts(converted into Vcard strings)stored in database
for(int i=0;i< dataArray.count;i++)
{
BOOL found = NO;
int phoneBookRecId=[[recordIDArray objectAtIndex:i] intValue];
NSString * currentPhVc=[dataArray objectAtIndex:i];
for(int j=0;j< dbArraywithRID.count;j++)
{
int dbRecId=[[dbArraywithRID objectAtIndex:j] intValue];
if(dbRecId == phoneBookRecId)
{
found =YES;
NSString * currentDBVc=[dbArraywithVcard objectAtIndex:j];
if(![currentDBVc isEqualToString:currentPhVc])
{
NSLog(@" db rec =%@ - %@ ",currentDBVc,currentPhVc );
[updateContactRecIds addObject:[NSNumber numberWithInt:phoneBookRecId]];
[newContact addObject:currentPhVc];
[newContactRecIds addObject:[NSNumber numberWithInt:phoneBookRecId]];
}
break;
}
}
if(!found)
{
[newContact addObject:currentPhVc];
[newContactRecIds addObject:[NSNumber numberWithInt:phoneBookRecId]];
}
}
if(newContact!=nil && [newContact count] > 0)
{
//newContact array contains all the contacts(vcard strings) that are new
}
if(updateContactRecIds!=nil && [updateContactRecIds count] > 0)
{
updateContactRecIds contains all the recordids which need to be updated
}
}