-
我正在尝试将所有联系人备份到服务器上。
-
所以我将触点转换为vcard字符串并发送
VCARD字符串到服务器上,还将VCARD字符串存储记录到SQLITE数据库 -
因此,用户第一次想要备份所有联系人将转到服务器以及数据库中。
-
从第二次开始,我只想将新联系人发送到服务器。因此,我需要比较存储的数据库记录IDID带有电话簿唱片的NSArray并获取新的记录到数组
-
例如,我有录音数,例如40,41,42,43,44,45dbarray.不一定按顺序或顺序。
-
现在,当用户添加5个新联系人电话簿阵列时,将包含录音等40,41,42,43,44,45,46,46,47,48,50
-
所以这次我只想发送与RecordID的联系人46,47,48,49和50。
-
我需要的是检查是否有任何修改存储的vcards。因此,我还需要比较电话簿阵列和数据库数组。
我是iOS编程的新手,我被卡住了。请帮助!!!它的紧急
i通过使用以下代码解决了上述问题。希望它可以帮助某人。
-(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
}
}