すべての連絡先のバックアップをサーバーに取り込もうとしています。
だから私は連絡先をvCard文字列に変換し、
vCard文字列をサーバーに送信し、RecordIDを含むvCard文字列をsqliteデータベースに保存していますしたがって、ユーザーが初めてバックアップを取りたい場合は、すべての連絡先がサーバーとデータベースに送信されます。
2回目からは、新しい連絡先のみをサーバーに送信したいと思います。したがって、nsarrayに格納されているデータベースのRecordIdをPhonebook RecordIdと比較し、新しいRecordIdを配列に取り込む必要があります。
たとえば、dbarrayに40、41、42、43、44、45のようなRecordIdがあります。必ずしも順序や順序である必要はありません。
これで、ユーザーが5つの新しい連絡先を追加すると、電話帳配列に40、41、42、43、44、45、46、47、48、50などのrecordIdが含まれるようになります。
したがって、今回はrecordIds 46、47、48、49、50の連絡先を送信したいだけです。増分バックアップのようなもの
また、保存されているvCardに変更がないかどうかを確認する必要があるため、電話帳配列とデータベース配列のすべてのvCard文字列を比較する必要もあります。
私はiOSプログラミングに不慣れで、行き詰まっています。助けてください!!!緊急です
1 に答える
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
}
}
于 2012-11-08T10:18:32.573 に答える