sincronizar pasar los importar exportar cómo contactos con ios objective-c frameworks ios9 contact

ios - pasar - sincronizar contactos iphone



Cómo importar contactos desde el contacto Marco ios9 (1)

Cómo agregar un número de teléfono múltiple usando Contact Framework iOS 9

CNMutableContact *contact = [test mutableCopy]; CNLabeledValue *homePhone_1 = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:[CNPhoneNumber phoneNumberWithStringValue:@"019312-555-1212"]]; CNLabeledValue * homePhone_2 = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:[CNPhoneNumber phoneNumberWithStringValue:@"312-555-1219"]]; [contact.phoneNumbers addObjectsFromArray:@[homePhone_1]]; [contact.phoneNumbers addObjectsFromArray:@[homePhone_2]]; CNSaveRequest *request = [[CNSaveRequest alloc] init]; [request updateContact:contact];

Por favor ayuda chicos. Esto no está funcionando.


Por favor, intente con el siguiente code .

- (void) addContact { CNMutableContact * contact = [CNMutableContact new]; contact.middleName = @"Testmiddle"; contact.contactType = CNContactTypePerson; contact.givenName = @"TestGivenname"; contact.familyName = @"Taken"; CNLabeledValue *homePhone_1 = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:[CNPhoneNumber phoneNumberWithStringValue:@"019312-555-1212"]]; CNLabeledValue * homePhone_2 = [CNLabeledValue labeledValueWithLabel:CNLabelWork value:[CNPhoneNumber phoneNumberWithStringValue:@"312-555-1219"]]; contact.phoneNumbers = @[homePhone_1, homePhone_2]; CNSaveRequest *request = [[CNSaveRequest alloc] init]; [request addContact:contact toContainerWithIdentifier:nil]; @try { CNContactStore * store = [CNContactStore new]; [store executeSaveRequest:request error:nil]; } @catch (NSException *exception) { NSLog(@"description = %@",[exception description]); } }

Para contacto de update necesita usar el siguiente code .

La obtención del contacto encapsula la operación de E / S por lo que le recomendé que los use en hilos de fondo. Si es necesario, puede enviar de manera segura los resultados de búsqueda inmutables al hilo principal

- (void)updateContact { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ CNContactStore * store = [CNContactStore new]; NSArray * arrFetchedcontact = [NSArray array]; @try { arrFetchedcontact = [store unifiedContactsMatchingPredicate:[CNContact predicateForContactsMatchingName:@"TestGivenname"] keysToFetch:[NSArray arrayWithObjects:@"CNContactGivenNameKey",@"CNContactFamilyNameKey",CNContactPhoneNumbersKey, nil] error:nil]; } @catch (NSException *exception) { NSLog(@"description = %@",[exception description]); } dispatch_async(dispatch_get_main_queue(), ^{ if([arrFetchedcontact count] > 0){ CNMutableContact * contact = [[arrFetchedcontact objectAtIndex:0] mutableCopy]; NSMutableArray * arrNumbers = [[contact phoneNumbers] mutableCopy]; CNLabeledValue * homePhone_2 = [CNLabeledValue labeledValueWithLabel:CNLabelOther value:[CNPhoneNumber phoneNumberWithStringValue:@"33333333333"]]; [arrNumbers addObject:homePhone_2]; contact.phoneNumbers = arrNumbers; CNSaveRequest *request = [[CNSaveRequest alloc] init]; [request updateContact:contact]; @try { [store executeSaveRequest:request error:nil]; } @catch (NSException *exception) { NSLog(@"description = %@",[exception description]); } } }); }); }