草庐IT

iphone - 检测从 ABAddressBookRegisterExternalChangeCallback 更改的内容

coder 2023-07-29 原文

我正在使用 ABAddressBookRegisterExternalChangeCallback 获取用户 AddressbookBook 中的外部更改。我正在使用以下代码来注册回调:

ABAddressBookRef ntificationaddressbook = ABAddressBookCreate();
ABAddressBookRegisterExternalChangeCallback(ntificationaddressbook, MyAddressBookExternalChangeCallback, self);

当这个回调被调用时,MyAddressBookExternalChangeCallback 被成功调用

void MyAddressBookExternalChangeCallback (ABAddressBookRef ntificationaddressbook,CFDictionaryRef info,void *context)
{
 NSLog(@"Changed Detected......");
}

我有以下问题:

  1. 如何检测更改了哪些联系人,以及对该联系人执行了哪些操作(ADD,Update,Delete)。我需要获取该联系人的记录 ID。可能吗 ?

不幸的是,如果那不可能,那么 viber、tango、watsapp 等应用程序如何获取更改信息?

  1. 只有当应用程序处于后台时我才会调用回调方法,如果应用程序已终止,是否有任何方法可以获取更改通知。

请帮忙。提前致谢。

最佳答案

我找到了查找地址簿中更改内容的解决方案。我不确定它是否准确,但知道它是如何工作的。

为地址簿创建回调通知:-

    ABAddressBookRef ntificationaddressbook = ABAddressBookCreate();
    ABAddressBookRegisterExternalChangeCallback(ntificationaddressbook, MyAddressBookExternalChangeCallback, self);

然后在通知发生时添加以下代码:-

void MyAddressBookExternalChangeCallback (ABAddressBookRef ntificationaddressbook,CFDictionaryRef info,void *context)
{
NSTimeInterval timeStampone = [[NSDate date] timeIntervalSince1970];
NSNumber *timeStamponeobj= [NSNumber numberWithDouble: timeStampone];
NSLog(@"Start Process");
NSUserDefaults *userdefs = [[NSUserDefaults alloc]init];
NSMutableArray *arraytemp = [[NSMutableArray alloc]init];
CFArrayRef peopleRefs = ABAddressBookCopyArrayOfAllPeopleInSource(ntificationaddressbook, kABSourceTypeLocal);
NSMutableArray *changedrecords = [[NSMutableArray alloc]init];
ABAddressBookRevert(ntificationaddressbook);
CFIndex count = CFArrayGetCount(peopleRefs);
for (CFIndex i=0; i < count; i++) {
    ABRecordRef ref = CFArrayGetValueAtIndex(peopleRefs, i);
    NSDate* datemod = ( NSDate *)(ABRecordCopyValue(ref, kABPersonModificationDateProperty));
    NSDate *lastopened = [userdefs valueForKey:@"LastOpenedDate"];
    NSTimeInterval datemodifiedtime =[datemod timeIntervalSince1970];
    NSNumber *modifieddatenumber= [NSNumber numberWithDouble: datemodifiedtime];
    NSTimeInterval lastopeddate = [lastopened timeIntervalSince1970];
    NSNumber *lastopenednumber= [NSNumber numberWithDouble: lastopeddate];
    if ([modifieddatenumber intValue]>[lastopenednumber intValue]) {
        ABRecordRef aSource = CFArrayGetValueAtIndex(peopleRefs,i);
         int recordid = ABRecordGetRecordID(aSource);
        [changedrecords addObject:[NSString stringWithFormat:@"%d",recordid]];
    }
}



NSString *arraystring= [changedrecords componentsJoinedByString:@","];
[userdefs setValue:arraystring forKey:@"ArrayOfChangedPeopleString"];
[userdefs setValue:changedrecords forKey:@"ArrayOfChangedPeople"];


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ([arraystring isEqualToString:@"(null)"]) {
    arraystring = [arraystring stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
}
NSLog(@"arraychangedstring= %@ and length = %d",arraystring,arraystring.length);

NSLog(@"Must send data to the server here for this changed people array= %@",changedrecords);
if (arraystring.length>2) {
    NSLog(@"inside if");
    ABAddressBookRef addressBook = ABAddressBookCreate();
    CFArrayRef allSources = ABAddressBookCopyArrayOfAllPeople( addressBook );
    [userdefs setValue:@"" forKey:@"ArrayOfChangedPeopleString"];
    [userdefs setValue:@"" forKey:@"ArrayOfChangedPeople"];
    for (int i = 0; i<[changedrecords count]; i++) {
        NSString *recordid= [changedrecords objectAtIndex:i];
        int nPeople = [recordid intValue];
        [IntoochUtil current_function_name:@"Inside getcontactdetails - Start"];

        if(nPeople != 0){
            //        for (CFIndex i = nPeople_start; i < (nPeople_end); i++)
            //        {
            //            NSString *reocrdid = [NSString stringWithFormat: @"Record %ld",i];
            //            NSLog(@"Recordid= %@",reocrdid);

            NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
            //common field
            NSString *first_name =nil;
            NSString *mid_name = nil ;
            NSString *last_name =nil ;
            NSString *basic_email =nil ;
            NSString *basic_mobile =nil ;
            NSString *other_phone=nil;
            NSString *pager_phone= nil;

            //personal filed
            NSString *Home_email =nil ;
            NSString*home_mobile =nil ;
            NSString*home_address =nil;
            //business filed
            NSString *work_email =nil ;
            NSString *company_name =nil ;
            NSString *job_title =nil ;
            NSString*work_mobile =nil ;
            NSString *iphone = nil;
            NSString *main = nil;
            NSString *work_address =nil ;

            NSString *home_fax, *work_fax, *other_fax =nil;
            NSString *birthday = nil;
            //            NSString *blogs = nil;

            NSString *record_id;
            ABRecordRef aSource = ABAddressBookGetPersonWithRecordID(addressBook, nPeople);
            // Fetch all groups included in the current source

            // Getting Record id from address book
            int recordid = ABRecordGetRecordID(aSource);
            record_id = [NSString stringWithFormat:@"%d",recordid];

            // Getting Names from address book
            //            CFStringRef firstName = ABRecordCopyValue(aSource, kABPersonFirstNameProperty);
            first_name= ABRecordCopyValue(aSource, kABPersonFirstNameProperty);
            //           first_name=[NSString stringWithFormat:@"%@",firstName];
            //           CFRelease(firstName);
            //            NSLog(@"First name= %@",first_name);
            NSMutableDictionary *dict_name = [[NSMutableDictionary alloc]init];
            if (!([first_name isEqualToString:@"(null)"]|| first_name == nil || first_name.length ==0))
            {
                [dict_name setValue:first_name forKey:@"FirstName"];

            }

            [first_name release];
            mid_name= ABRecordCopyValue(aSource, kABPersonMiddleNameProperty);
            //            NSLog(@"mid name = %@",mid_name);
            //            CFRelease(midname);
            if (!([mid_name isEqualToString:@"(null)"]|| mid_name == nil || mid_name.length ==0))
            {
                [dict_name setValue:mid_name forKey:@"MiddleName"];

            }
            [mid_name release];
            last_name = ABRecordCopyValue(aSource, kABPersonLastNameProperty);
            //            NSLog(@"Last Name= %@",last_name);
            //            CFRelease(lastName);
            if (!([last_name isEqualToString:@"(null)"]|| last_name == nil || last_name.length ==0))
            {
                [dict_name setValue:last_name forKey:@"LastName"];
            }
            [last_name release];
            NSString *dictNamestring = [NSString stringWithFormat:@"%@",dict_name];
            if (!([dictNamestring isEqualToString:@"(null)"]|| dictNamestring == nil || dictNamestring.length <4))
            {
                [dict setValue:dict_name forKey:@"Names"];
            }
            //            [dict_name release];

            // Getting Phone numbers from address book
            NSMutableDictionary *dict_phone = [[NSMutableDictionary alloc]init];
            ABMultiValueRef phones =(NSString*)ABRecordCopyValue(aSource, kABPersonPhoneProperty);
            NSString* mobileLabel;
            for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
                mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
                if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
                {
                    home_mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i) ;
                    [dict_phone setValue:home_mobile forKey:@"Mobile"];
                }

                else if ([mobileLabel isEqualToString:(NSString*)kABHomeLabel])
                {
                    basic_mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
                    [dict_phone setValue:basic_mobile forKey:@"Home"];
                }

                else if([mobileLabel isEqualToString:(NSString *)kABWorkLabel])
                {
                    work_mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
                    [dict_phone setValue:work_mobile forKey:@"Work"];
                }
                else if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneIPhoneLabel])
                {
                    iphone = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
                    [dict_phone setValue:iphone forKey:@"iPhone"];
                }
                else if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMainLabel])
                {
                    main = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
                    [dict_phone setValue:main forKey:@"Main"];
                }

                else if ([mobileLabel isEqualToString:(NSString*)kABOtherLabel])
                {
                    other_phone = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
                    [dict_phone setValue:other_phone forKey:@"OtherPhone"];
                }
                else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhonePagerLabel])
                {
                    pager_phone = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
                    [dict_phone setValue:pager_phone forKey:@"Pager"];
                }
                else
                {
                    NSLog(@"%@ label is not processed",mobileLabel);
                }
            }
            CFRelease(phones);
            NSString *dictphonestring = [NSString stringWithFormat:@"%@",dict_phone];
            if (!([dictphonestring isEqualToString:@"(null)"]|| dictphonestring == nil || dictphonestring.length <4))
            {
                [dict setValue:dict_phone forKey:@"PhoneNos"];
            }
            //            [dict_phone release];

            // Getting Fax numbers from address book
            NSMutableDictionary *dict_fax = [[NSMutableDictionary alloc]init];
            ABMultiValueRef faxes =(NSString*)ABRecordCopyValue(aSource, kABPersonPhoneProperty);
            NSString* FaxLabel;
            for(CFIndex i = 0; i < ABMultiValueGetCount(faxes); i++) {
                FaxLabel = (NSString*)ABMultiValueCopyLabelAtIndex(faxes, i);
                if([FaxLabel isEqualToString:(NSString *)kABPersonPhoneHomeFAXLabel])
                {
                    home_fax = (NSString*)ABMultiValueCopyValueAtIndex(faxes, i) ;
                    [dict_fax setValue:home_fax forKey:@"Home"];
                }
                if ([FaxLabel isEqualToString:(NSString*)kABPersonPhoneWorkFAXLabel])
                {
                    work_fax = (NSString*)ABMultiValueCopyValueAtIndex(faxes, i);
                    [dict_fax setValue:work_fax forKey:@"Work"];

                }
                if([FaxLabel isEqualToString:(NSString *)kABPersonPhoneOtherFAXLabel])
                {
                    other_fax = (NSString*)ABMultiValueCopyValueAtIndex(faxes, i);
                    [dict_fax setValue:other_fax forKey:@"Other"];
                }
            }
            CFRelease(faxes);
            NSString *dictfaxstring = [NSString stringWithFormat:@"%@",dict_fax];

            if (!([dictfaxstring isEqualToString:@"(null)"]|| dictfaxstring == nil || dictfaxstring.length <4))
            {
                [dict setValue:dict_fax forKey:@"FaxNos"];
            }
            [dict_fax release];

            // Getting emails from address book
            ABMultiValueRef email = ABRecordCopyValue(aSource, kABPersonEmailProperty);
            NSMutableDictionary *dict_email = [[NSMutableDictionary alloc]init];
            NSString* email_lbl;


            for(CFIndex i = 0; i < ABMultiValueGetCount(email); i++) {
                email_lbl = (NSString*)ABMultiValueCopyLabelAtIndex(email, i);

                if([email_lbl isEqualToString:(NSString *)kABHomeLabel])
                {
                    Home_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
                    [dict_email setValue:Home_email forKey:@"Home"];
                }
                else if([email_lbl isEqualToString:(NSString *)kABWorkLabel])
                {
                    work_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
                    [dict_email setValue:work_email forKey:@"Work"];

                }
                else if([email_lbl isEqualToString:(NSString *)kABOtherLabel])
                {
                    basic_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];

                    [dict_email setValue:basic_email forKey:@"Other"];
                }
                else
                {
                    NSLog(@"%@ label is processed as other",email_lbl);
                    basic_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
                    [dict_email setValue:basic_email forKey:@"Other"];

                }

            }
            CFRelease(email);
            NSString *dictemailstring = [NSString stringWithFormat:@"%@",dict_email];
            if (!([dictemailstring isEqualToString:@"(null)"]|| dictemailstring == nil || dictemailstring.length <4))
            {
                [dict setValue:dict_email forKey:@"Emails"];
            }
            //            [dict_email release];


            company_name = ABRecordCopyValue(aSource, kABPersonOrganizationProperty);
            //            NSLog(@"Company name= %@",company_name);
            job_title = ABRecordCopyValue(aSource, kABPersonJobTitleProperty);
            //            NSLog(@"Job title= %@",job_title);
            NSDate *birthdate = ABRecordCopyValue(aSource, kABPersonBirthdayProperty);
            NSString *birthdate_string = [NSString stringWithFormat:@"%@",birthdate];
            if (!([birthdate_string isEqualToString:@"(null)"]|| birthdate_string == nil || birthdate_string.length ==0)) {
                NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:birthdate];
                NSInteger day = [components day];
                NSInteger month = [components month];
                NSInteger year = [components year];
                birthday = [NSString stringWithFormat:@"%d-%d-%d",day,month,year];
                NSLog(@"birthday= %@",birthday);

            }
            [birthdate release];




            // Getting addressess from address book
            ABMultiValueRef address =(NSString*)ABRecordCopyValue(aSource, kABPersonAddressProperty);
            NSDictionary *dict_address = [[NSMutableDictionary alloc]init];

            NSString* addLabel;
            for(CFIndex i = 0; i < ABMultiValueGetCount(address); i++) {
                addLabel=(NSString*)ABMultiValueCopyLabelAtIndex(address, i);
                if ([addLabel isEqualToString:(NSString*)kABWorkLabel])     {
                    NSMutableDictionary *dict_work_add = [(NSMutableDictionary *)ABMultiValueCopyValueAtIndex(address, i)retain];
                    work_address=[NSString stringWithFormat:@"%@ %@ %@ %@ %@",[dict_work_add objectForKey:@"Street"],[dict_work_add objectForKey:@"City"],[dict_work_add objectForKey:@"State"],[dict_work_add objectForKey:@"Country"],[dict_work_add objectForKey:@"ZIP"]] ;
                    work_address = [work_address stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
                    work_address = [work_address stringByReplacingOccurrencesOfString:@"\n" withString:@""];
                    //                    NSLog(@"work address = [%@] and length= %d",work_address,work_address.length);
                    if (!([work_address isEqualToString:@"(null)"]|| work_address == nil || work_address.length ==0))
                    {
                        [dict_address setValue:work_address forKey:@"Work"];
                    }
                }
                if ([addLabel isEqualToString:(NSString*)kABHomeLabel])
                {
                    NSMutableDictionary *dict_home_add = [(NSMutableDictionary *)ABMultiValueCopyValueAtIndex(address, i)retain];

                    home_address = [NSString stringWithFormat:@"%@ %@ %@ %@ %@",[dict_home_add objectForKey:@"Street"],[dict_home_add objectForKey:@"City"],[dict_home_add objectForKey:@"State"],[dict_home_add objectForKey:@"Country"],[dict_home_add objectForKey:@"ZIP"]];
                    home_address = [home_address stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
                    home_address = [home_address stringByReplacingOccurrencesOfString:@"\n" withString:@""];
                    //                    NSLog(@"home address = [%@] and length= %d",home_address,home_address.length);
                    if (!([home_address isEqualToString:@"(null)"]|| home_address == nil || home_address.length ==0))
                    {
                        [dict_address setValue:home_address forKey:@"Home"];
                    }
                }
            }
            CFRelease(address);
            NSString *dictaddrssstring = [NSString stringWithFormat:@"%@",dict_address];
            if (!([dictaddrssstring isEqualToString:@"(null)"]|| dictaddrssstring == nil || dictaddrssstring.length <4))
            {
                [dict setValue:dict_address forKey:@"Addresses"];
            }
            [dict_address release];
            // Getting Social Networks from address book
            ABMultiValueRef social =(NSString*)ABRecordCopyValue(aSource, kABPersonSocialProfileProperty);
            NSMutableDictionary *dict_social = [[NSMutableDictionary alloc]init];
            if (social) {
                for (int i = 0 ; i < ABMultiValueGetCount(social); i++) {
                    NSDictionary *socialDict = (NSDictionary *)ABMultiValueCopyValueAtIndex(social, i);
                    NSString *twitterid;
                    if ([socialDict[@"service"] isEqualToString:(NSString*)kABPersonSocialProfileServiceTwitter]) {
                        twitterid = (NSString*)socialDict[@"username"];
                        [dict_social setValue:twitterid forKey:@"Twitter"];
                    }

                    NSString *facebookid;
                    if ([socialDict[@"service"] isEqualToString:(NSString*)kABPersonSocialProfileServiceFacebook]) {
                        facebookid = (NSString*)socialDict[@"username"];
                        [dict_social setValue:facebookid forKey:@"Facebook"];
                    }

                    NSString *linkedinid;
                    if ([socialDict[@"service"] isEqualToString:(NSString*)kABPersonSocialProfileServiceLinkedIn]) {
                        linkedinid = (NSString*)socialDict[@"username"];
                        [dict_social setValue:linkedinid forKey:@"LinkedIn"];
                    }

                    NSString *gamecenterid;
                    if ([socialDict[@"service"] isEqualToString:(NSString*)kABPersonSocialProfileServiceGameCenter]) {
                        gamecenterid = (NSString*)socialDict[@"username"];
                        [dict_social setValue:gamecenterid forKey:@"GameCenter"];
                    }

                    NSString *myspaceid;
                    if ([socialDict[@"service"] isEqualToString:(NSString*)kABPersonSocialProfileServiceMyspace]) {
                        myspaceid = (NSString*)socialDict[@"username"];
                        [dict_social setValue:myspaceid forKey:@"MySpace"];

                    }
                    NSString *flickerid;
                    if ([socialDict[@"service"] isEqualToString:(NSString*)kABPersonSocialProfileServiceFlickr]) {
                        flickerid = (NSString*)socialDict[@"username"];
                        [dict_social setValue:flickerid forKey:@"Flicker"];
                    }
                    [socialDict release];
                }
                CFRelease(social);

            }

            NSString *dictsocialstring = [NSString stringWithFormat:@"%@",dict_social];
            if (!([dictsocialstring isEqualToString:@"(null)"]|| dictsocialstring == nil || dictsocialstring.length <4))
            {
                [dict setValue:dict_social forKey:@"SocialNetworks"];
            }
            [dict_social release];

            // Getting Other Fields from address book
            NSMutableDictionary *dict_others = [[NSMutableDictionary alloc]init];
            if (!([company_name isEqualToString:@"(null)"]||company_name == nil || company_name.length ==0)) {
                [dict_others setValue:company_name forKey:@"CompanyName"];
            }
            if (!([job_title isEqualToString:@"(null)"]||job_title == nil || job_title.length ==0)) {
                [dict_others setValue:job_title forKey:@"JobTitle"];
            }
            if (!([birthday isEqualToString:@"1-1-2001"]||[birthday isEqualToString:@"(null)"]||birthday == nil || birthday.length ==0)) {

                [dict_others setValue:birthday forKey:@"BirthDay"];


            }
            NSString *dictothersstring = [NSString stringWithFormat:@"%@",dict_others];
            if (!([dictothersstring isEqualToString:@"(null)"]|| dictothersstring == nil || dictothersstring.length <4))
            {
                [dict setValue:dict_others forKey:@"OtherInfo"];
            }
            [dict_others release];
            [dict setValue:record_id forKey:@"RecordID"];
            //This            NSLog(@"Value for Dict is========= %@ =========",dict);

            NSString *namedictionstring = [NSString stringWithFormat:@"%@",dict_name];
            NSString *emaildictstring = [NSString stringWithFormat:@"%@",dict_email];
            NSString *phonedictstring = [NSString stringWithFormat:@"%@",dict_phone];


            //           NSLog(@"name dict length= %d email dict length= %d phone dict length = %d",namedictionstring.length,emaildictstring.length,phonedictstring.length);


            //            [array_addressbook addObject:dict];


            if (phonedictstring.length >3) {
                [arraytemp addObject:dict];
            }
            else
            {
                if (emaildictstring.length>3 && namedictionstring.length) {
                    [arraytemp addObject:dict] ;
                }
                else
                {
                    NSLog(@"Contact is not valid= %@",dict_name);
                }
            }


            [dict_name release];
            [dict_phone release];
            [dict_email release];
            [dict release];
            [company_name release];
            [job_title release];
            /*            CFRelease(firstName);
             CFRelease(midname);
             CFRelease(lastName);
             CFRelease(jobtitle);
             CFRelease(birthday_c);
             CFRelease(companyname);*/
            //        }

        }
    }
        NSString *json_array_string = [arraytemp JSONRepresentation];
        [IntoochUtil current_function_name:@"Inside getcontactdetails - End"];
        NSLog(@"Json String To send= %@",json_array_string);


    if (allSources) {
        CFRelease(allSources);
    }
    if (addressBook) {
        CFRelease(addressBook);
    }
}

else
{
    NSLog(@"This is empty.... nothing to perform");
    NSMutableArray *arrayofdeletedpeoples= [[NSMutableArray alloc]init];
    ABAddressBookRef addressbook = ABAddressBookCreate();
    CFArrayRef allPeoples= ABAddressBookCopyArrayOfAllPeople(addressbook);
    NSMutableArray *arrayofrecordIDCallback = [[NSMutableArray alloc]init];
    int count = CFArrayGetCount(allPeoples);
    for (int i =0; i<count; i++) {
        ABRecordRef aSource = CFArrayGetValueAtIndex(allPeoples,i);
        NSString * recordid = [NSString stringWithFormat:@"%d",ABRecordGetRecordID(aSource)];
        [arrayofrecordIDCallback addObject:recordid];
    }
    NSLog(@"arrayofrecordIDCallback = %@ and count= %d",arrayofrecordIDCallback,[arrayofrecordIDCallback count]);
    NSMutableArray *arrayofallrecordids = [userdefs valueForKey:@"AllRecordIDSBackGround"];
    NSLog(@"arrayofallrecordids= %@ and count= %d",arrayofallrecordids,[arrayofallrecordids count]);
    for (int i=0 ; i< [arrayofallrecordids count]; i++) {
        if ([arrayofrecordIDCallback containsObject:[arrayofallrecordids objectAtIndex:i]]) {
        }
        else
        {
            [arrayofdeletedpeoples addObject:[arrayofallrecordids objectAtIndex:i]];
        }
    }

    NSLog(@"Array of deleted peoples= %@",arrayofdeletedpeoples);

    [arrayofdeletedpeoples release];
    [arrayofallrecordids release];
    [arrayofrecordIDCallback release];
    if (allPeoples) {
        CFRelease(allPeoples);
    }
    if (addressbook) {
        CFRelease(addressbook);
    }

}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[changedrecords release];
[userdefs release];
[arraytemp release];
NSLog(@"Ends Process");
NSTimeInterval timeStamptwo = [[NSDate date] timeIntervalSince1970];
NSNumber *timeStamptwoObj = [NSNumber numberWithDouble: timeStamptwo];
NSLog(@"Time Difference= %d",[timeStamptwoObj intValue]-[timeStamponeobj intValue]);
}

关于iphone - 检测从 ABAddressBookRegisterExternalChangeCallback 更改的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17440115/

有关iphone - 检测从 ABAddressBookRegisterExternalChangeCallback 更改的内容的更多相关文章

  1. ruby-on-rails - Ruby on Rails 迁移,将表更改为 MyISAM - 2

    如何正确创建Rails迁移,以便将表更改为MySQL中的MyISAM?目前是InnoDB。运行原始执行语句会更改表,但它不会更新db/schema.rb,因此当在测试环境中重新创建表时,它会返回到InnoDB并且我的全文搜索失败。我如何着手更改/添加迁移,以便将现有表修改为MyISAM并更新schema.rb,以便我的数据库和相应的测试数据库得到相应更新? 最佳答案 我没有找到执行此操作的好方法。您可以像有人建议的那样更改您的schema.rb,然后运行:rakedb:schema:load,但是,这将覆盖您的数据。我的做法是(假设

  2. ruby - 将数组的内容转换为 int - 2

    我需要读入一个包含数字列表的文件。此代码读取文件并将其放入二维数组中。现在我需要获取数组中所有数字的平均值,但我需要将数组的内容更改为int。有什么想法可以将to_i方法放在哪里吗?ClassTerraindefinitializefile_name@input=IO.readlines(file_name)#readinfile@size=@input[0].to_i@land=[@size]x=1whilex 最佳答案 只需将数组映射为整数:@land边注如果你想得到一条线的平均值,你可以这样做:values=@input[x]

  3. ruby-on-rails - 项目升级后 Pow 不会更改 ruby​​ 版本 - 2

    我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby​​版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby​​版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘

  4. ruby - Capistrano 3 在任务中更改 ssh_options - 2

    我尝试使用不同的ssh_options在同一阶段运行capistranov.3任务。我的production.rb说:set:stage,:productionset:user,'deploy'set:ssh_options,{user:'deploy'}通过此配置,capistrano与用户deploy连接,这对于其余的任务是正确的。但是我需要将它连接到服务器中配置良好的an_other_user以完成一项特定任务。然后我的食谱说:...taskswithoriginaluser...task:my_task_with_an_other_userdoset:user,'an_othe

  5. ruby-on-rails - 如何在我的 Rails 应用程序 View 中打印 ruby​​ 变量的内容? - 2

    我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby​​中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R

  6. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  7. ruby - 查找字符串中的内容类型(数字、日期、时间、字符串等) - 2

    我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s

  8. ruby - 更改 ActiveRecord 中对象的类 - 2

    假设我有一个FireNinja我的数据库中的对象,使用单表继承存储。后来才知道他真的是WaterNinja.将他更改为不同的子类的最干净的方法是什么?更好的是,我很想创建一个新的WaterNinja对象并替换旧的FireNinja在数据库中,保留ID。编辑我知道如何创建新的WaterNinja来self现有FireNinja的对象,我也知道我可以删除旧的并保存新的。我想做的是改变现有项目的类别。我是通过创建一个新对象并执行一些ActiveRecord魔法来替换行,还是通过对对象本身做一些疯狂的事情,或者甚至通过删除它并使用相同的ID重新插入来做到这一点,这是问题的一部分。

  9. python - 如何读取 MIDI 文件、更改其乐器并将其写回? - 2

    我想解析一个已经存在的.mid文件,改变它的乐器,例如从“acousticgrandpiano”到“violin”,然后将它保存回去或作为另一个.mid文件。根据我在文档中看到的内容,该乐器通过program_change或patch_change指令进行了更改,但我找不到任何在已经存在的MIDI文件中执行此操作的库.他们似乎都只支持从头开始创建的MIDI文件。 最佳答案 MIDIpackage会为您完成此操作,但具体方法取决于midi文件的原始内容。一个MIDI文件由一个或多个音轨组成,每个音轨是十六个channel中任何一个上的

  10. ruby - 如何使用 Selenium Webdriver 根据 div 的内容执行操作? - 2

    我有一个使用SeleniumWebdriver和Nokogiri的Ruby应用程序。我想选择一个类,然后对于那个类对应的每个div,我想根据div的内容执行一个Action。例如,我正在解析以下页面:https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=puppies这是一个搜索结果页面,我正在寻找描述中包含“Adoption”一词的第一个结果。因此机器人应该寻找带有className:"result"的div,对于每个检查它的.descriptiondiv是否包含单词“adoption

随机推荐