ExternalChange地址簿

时间:2016-04-04 11:54:22

标签: c# ios xamarin

帮助。我试着跟踪地址簿中的变化。但方法

NSError err;
ABAddressBook iOSAddressBook = ABAddressBook.Create(out err);
iOSAddressBook.ExternalChange += (object sender, ExternalChangeEventArgs e) =>
    {
        Console.WriteLine("qorkkkk");
    };

不起作用。

1 个答案:

答案 0 :(得分:-1)

/*First, Make change in viewDidLoad Method from where you want to change addressbook Record.*/
- (void)viewDidLoad {
  ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil, nil);
    ABAddressBookRegisterExternalChangeCallback(addressBook, addressBookChanged, (__bridge void *)(self));
}
//Then,
    /*------- method will call when contact updated  ------*/
void addressBookChanged(ABAddressBookRef addressBook, CFDictionaryRef info, void *context)
{
    @try {
        [YourVewControllerObj updateRecord];
//        YourViewController *viewController = (__bridge YourViewController*)context;
//        [viewController updateRecord];
    }
    @catch (NSException *exception) {
        NSLog(@"%@",exception.description);
    }
}

    /*------- Method call if make any change in conatct ------*/
+(void)updateRecord
{
  NSMutableDictionary *dictPerson= [NSMutableDictionary dictionary];
    CFErrorRef error = NULL;
    ABAddressBookRef addressBook =ABAddressBookCreateWithOptions(NULL, &error) ;
    ABRecordID record = ABRecordGetRecordID(ABRecordRef);
    ABRecordRef contactPerson = ABAddressBookGetPersonWithRecordID(addressBook, record);
/*---Here you get your updated Record Refence----*/
//Do your other stuff here
}