CNContactStoreDidChangeNotification is fired multiple times

后端 未结 3 757
感情败类
感情败类 2020-12-30 22:50

I am able to observe the CNContactStoreDidChangeNotification when the contact database is changed while the app is in background state. I am pretty sure that on

3条回答
  •  梦谈多话
    2020-12-30 23:49

    I had the same problem, the number of times it fired varied between 2 & 3. The solution that worked for me was to set a semaphore variable, set in the handler and reset the semaphore when finished. Wrap the address book processing in an if statement on the semaphore to ignore further calls. addressBkSemphore is reset to false in buildFrendsAndContacts

    - (void)addressBkChange:(NSNotification *)note
    {   
        if (addressBkSemphore == false)
        {
            addressBkSemphore = TRUE;
            [self buildFrendsAndContacts];
        }
    }
    

    Hope it helps.

提交回复
热议问题