ios - app get crash after contacts gets added from address book to sqlite database -


this how add contact information in database addressbook

abaddressbookref addressbook = abaddressbookcreate();     cfarrayref allpeoplename = abaddressbookcopyarrayofallpeople(addressbook);     cfindex npeoplename = abaddressbookgetpersoncount(addressbook);     nsdateformatter *dateformat = [[nsdateformatter alloc] init];     [dateformat setdateformat:@"mm/dd/yyyy"];      for( int = 0 ; < npeoplename ; i++ )     {         abrecordref ref = cfarraygetvalueatindex(allpeoplename, );         nsstring* personname = (__bridge_transfer nsstring*) abrecordcopyvalue(ref, kabpersonfirstnameproperty);         nsdate* date = (__bridge_transfer nsdate*) abrecordcopyvalue(ref, kabpersonbirthdayproperty);           cfstringref value, label;         abmutablemultivalueref multi = abrecordcopyvalue(ref, kabpersonemailproperty);         cfindex count = abmultivaluegetcount(multi);         if (count == 1) {             value = abmultivaluecopyvalueatindex(multi, 0);             nsstring* emailaddress =    (nsstring*)value;             [emailaddress retain];             cfrelease(value);             [_emailarray addobject:emailaddress];             nslog(@"_emailarray%@",_emailarray);          } else {             (cfindex = 0; < count; i++) {                 label = abmultivaluecopylabelatindex(multi, i);                 value = abmultivaluecopyvalueatindex(multi, i);                  // check home e-mail label                 // can put if else here there checking home can check more work , , , can provoide email id can see code below else if there , email id ever can got it?                   if (label && cfstringcompare(label, kabhomelabel, 0) == 0) {                     nsstring* emailaddress = (nsstring*)value;                     [emailaddress retain];                      nslog(@"date%@",date);                     if (date != nil) {                      [_emailarray addobject:emailaddress];                      }                     nslog(@"_emailarray%@",_emailarray);                     break;                 }                  cfrelease(label);                 cfrelease(value);             }         }         if (_emailarray.count == i) {             nslog(@"_emailarray.count %d",_emailarray.count);              [_emailarray addobject:[nsstring stringwithstring:@"add email"]];              nslog(@"_emailarray%@",_emailarray);         }         cfrelease(multi);           nsstring *birthdaydate = [dateformat stringfromdate:date];            abmultivalueref phones = (abmultivalueref)abrecordcopyvalue(ref, kabpersonphoneproperty);         nsstring* mobile=@"";         nsstring* mobilelabel;         (int i=0; < abmultivaluegetcount(phones); i++) {             //nsstring *phone = (nsstring *)abmultivaluecopyvalueatindex(phones, i);             //nslog(@"%@", phone);             // right you getting mobile number plcaes check condition available in addressbook , phone number put more else if condition , there go got ?              mobilelabel = (nsstring*)abmultivaluecopylabelatindex(phones, i);             if([mobilelabel isequaltostring:(nsstring *)kabpersonphonemobilelabel]) {                 nslog(@"mobile:");             } else if ([mobilelabel isequaltostring:(nsstring*)kabpersonphoneiphonelabel]) {                 nslog(@"iphone:");             } else if ([mobilelabel isequaltostring:(nsstring*)kabpersonphonepagerlabel]) {                 nslog(@"pager:");             }             [mobile release];             mobile = (nsstring*)abmultivaluecopyvalueatindex(phones, i);             nslog(@"%@", mobile);             nscharacterset* characterstoremove = [[nscharacterset decimaldigitcharacterset] invertedset] ;             mobile = [[mobile componentsseparatedbycharactersinset:characterstoremove] componentsjoinedbystring:@""] ;           }            nsstring *holderstring = [[nsstring alloc]initwithstring:@"add number"];           if (birthdaydate != nil){               [_birthdateincontects addobject:birthdaydate];             nslog(@"_birthdateincontects%@",_birthdateincontects);              if([mobile isequaltostring:@""]){                 [_phonearray addobject:holderstring];                   nslog(@"_phonearray%@",_phonearray);               }              else{                 [_phonearray addobject:mobile];                 nslog(@"_phonearray%@",_phonearray);                }             if(personname != nil){                  [_namesincontects addobject:personname];                 nslog(@"_namesincontects%@",_namesincontects);               }             else{                 [_namesincontects addobject:@"no name"];                  nslog(@"_namesincontects%@",_namesincontects);               }           }          nslog(@"_namesincontects%@",_namesincontects);         nslog(@"_birthdateincontects%@",_birthdateincontects);         nslog(@"_phonearray%@",_phonearray);         nslog(@"_emailarray%@",_emailarray);        }          contentstring = [[nsmutablestring alloc]init];      char *update = "insert personnamesandbirthdates (names,birthdates,phonenumber,email,profilepic) values(?,?,?,?,?);";     sqlite3_stmt *stmt;     int x;      if ((x = sqlite3_prepare_v2(database1, update, -1, &stmt, nil)) != sqlite_ok)     {         nslog(@"%s: prepare failed: %s (%d)", __function__, sqlite3_errmsg(database1), x);         return;     }      (int = 0; < _birthdateincontects.count; i++)     {          [contentstring appendstring:[_namesincontects objectatindex:i]];         if(i !=_birthdateincontects.count-1){         [contentstring appendstring:@", "];         }           sqlite3_bind_text(stmt, 1, [[nsstring stringwithformat:@"%@",[_namesincontects objectatindex:i]] utf8string],-1, null);         sqlite3_bind_text(stmt, 2, [[nsstring stringwithformat:@"%@",[_birthdateincontects objectatindex:i]] utf8string],-1, null);         sqlite3_bind_text(stmt, 3, [[nsstring stringwithformat:@"%@",[_phonearray objectatindex:i]] utf8string],-1, null);         sqlite3_bind_text(stmt, 4, [[nsstring stringwithformat:@"%@",[_emailarray objectatindex:i]] utf8string],-1, null);          sqlite3_bind_text(stmt, 5,[[nsstring stringwithformat:@"%@",@"no image"] utf8string],-1, null);                 if ((x = sqlite3_step(stmt)) != sqlite_done) {             nslog(@"%s: step failed: %s (%d)", __function__, sqlite3_errmsg(database1), x);         }          sqlite3_reset(stmt);     }       sqlite3_finalize(stmt);        nslog(@"contentstring%@",contentstring);      if([contentstring length] != 0){          [[[uialertview alloc] initwithtitle:@"friends added addressbook:"                                      message:contentstring                                     delegate:nil                            cancelbuttontitle:@"ok"                            otherbuttontitles:nil]           show];      }       [_namesincontects removeallobjects];     [_birthdateincontects removeallobjects];     [_phonearray removeallobjects];     [_emailarray removeallobjects];       [uialertview release];     [contentstring release];    } 

data added in sqlite database works fine uialertview appears , stuck when put breakpoint reaches main.m

 return uiapplicationmain(argc, argv, nil, nsstringfromclass([appdelegate class])); 

and says exe_bad_access

in consol says

  single stepping until exit function objc_release,  has no line number information. (gdb)  

can please check code , can update something? trying solve long time nothing helped

note: 2 times out of 10 times app not getting crashed

abaddressbookref addressbook = abaddressbookcreate();     cfarrayref allpeoplename = abaddressbookcopyarrayofallpeople(addressbook);     cfindex npeoplename = abaddressbookgetpersoncount(addressbook);     nsdateformatter *dateformat = [[nsdateformatter alloc] init];     [dateformat setdateformat:@"mm/dd/yyyy"];      for( int = 0 ; < npeoplename ; i++ )     {         abrecordref ref = cfarraygetvalueatindex(allpeoplename, );         nsstring* personname = (__bridge_transfer nsstring*) abrecordcopyvalue(ref, kabpersonfirstnameproperty);         nsdate* date = (__bridge_transfer nsdate*) abrecordcopyvalue(ref, kabpersonbirthdayproperty);           cfstringref value, label;         abmutablemultivalueref multi = abrecordcopyvalue(ref, kabpersonemailproperty);         cfindex count = abmultivaluegetcount(multi);         if (count == 1) {             value = abmultivaluecopyvalueatindex(multi, 0);             nsstring* emailaddress =    (nsstring*)value;             [emailaddress retain];             cfrelease(value);             [_emailarray addobject:emailaddress];             nslog(@"_emailarray%@",_emailarray);          } else {             (cfindex = 0; < count; i++) {                 label = abmultivaluecopylabelatindex(multi, i);                 value = abmultivaluecopyvalueatindex(multi, i);                  // check home e-mail label                 // can put if else here there checking home can check more work , , , can provoide email id can see code below else if there , email id ever can got it?                   if (label && cfstringcompare(label, kabhomelabel, 0) == 0) {                     nsstring* emailaddress = (nsstring*)value;                     [emailaddress retain];                      nslog(@"date%@",date);                     if (date != nil) {                      [_emailarray addobject:emailaddress];                      }                     nslog(@"_emailarray%@",_emailarray);                     break;                 }                  //cfrelease(label);                // cfrelease(value);             }         }         if (_emailarray.count == i) {             nslog(@"_emailarray.count %d",_emailarray.count);              [_emailarray addobject:[nsstring stringwithstring:@"add email"]];              nslog(@"_emailarray%@",_emailarray);         }        // cfrelease(multi);           nsstring *birthdaydate = [dateformat stringfromdate:date];            abmultivalueref phones = (abmultivalueref)abrecordcopyvalue(ref, kabpersonphoneproperty);         nsstring* mobile=@"";         nsstring* mobilelabel;         (int i=0; < abmultivaluegetcount(phones); i++) {             //nsstring *phone = (nsstring *)abmultivaluecopyvalueatindex(phones, i);             //nslog(@"%@", phone);             // right you getting mobile number plcaes check condition available in addressbook , phone number put more else if condition , there go got ?              mobilelabel = (nsstring*)abmultivaluecopylabelatindex(phones, i);             if([mobilelabel isequaltostring:(nsstring *)kabpersonphonemobilelabel]) {                 nslog(@"mobile:");             }             else if ([mobilelabel isequaltostring:(nsstring*)kabpersonphoneiphonelabel]) {                 nslog(@"iphone:");             }              else if ([mobilelabel isequaltostring:(nsstring*)kabpersonphonemainlabel]) {                 nslog(@"main:");              }              else if ([mobilelabel isequaltostring:(nsstring*)kabpersonphonepagerlabel]) {                 nslog(@"pager:");             }         //    [mobile release];             mobile = (nsstring*)abmultivaluecopyvalueatindex(phones, i);             nslog(@"%@", mobile);             nscharacterset* characterstoremove = [[nscharacterset decimaldigitcharacterset] invertedset] ;             mobile = [[mobile componentsseparatedbycharactersinset:characterstoremove] componentsjoinedbystring:@""] ;           }            nsstring *holderstring = [[nsstring alloc]initwithstring:@"add number"];           if (birthdaydate != nil){               [_birthdateincontects addobject:birthdaydate];             nslog(@"_birthdateincontects%@",_birthdateincontects);              if([mobile isequaltostring:@""]){                 [_phonearray addobject:holderstring];                   nslog(@"_phonearray%@",_phonearray);               }              else{                 [_phonearray addobject:mobile];                 nslog(@"_phonearray%@",_phonearray);                }             if(personname != nil){                  [_namesincontects addobject:personname];                 nslog(@"_namesincontects%@",_namesincontects);               }             else{                 [_namesincontects addobject:@"no name"];                  nslog(@"_namesincontects%@",_namesincontects);               }           }          nslog(@"_namesincontects%@",_namesincontects);         nslog(@"_birthdateincontects%@",_birthdateincontects);         nslog(@"_phonearray%@",_phonearray);         nslog(@"_emailarray%@",_emailarray);        }          contentstring = [[nsmutablestring alloc]init];      char *update = "insert personnamesandbirthdates (names,birthdates,phonenumber,email,profilepic) values(?,?,?,?,?);";     sqlite3_stmt *stmt;     int x;      if ((x = sqlite3_prepare_v2(database1, update, -1, &stmt, nil)) != sqlite_ok)     {         nslog(@"%s: prepare failed: %s (%d)", __function__, sqlite3_errmsg(database1), x);         return;     }      (int = 0; < _birthdateincontects.count; i++)     {          [contentstring appendstring:[_namesincontects objectatindex:i]];         if(i !=_birthdateincontects.count-1){         [contentstring appendstring:@", "];         }           sqlite3_bind_text(stmt, 1, [[nsstring stringwithformat:@"%@",[_namesincontects objectatindex:i]] utf8string],-1, null);         sqlite3_bind_text(stmt, 2, [[nsstring stringwithformat:@"%@",[_birthdateincontects objectatindex:i]] utf8string],-1, null);         sqlite3_bind_text(stmt, 3, [[nsstring stringwithformat:@"%@",[_phonearray objectatindex:i]] utf8string],-1, null);         sqlite3_bind_text(stmt, 4, [[nsstring stringwithformat:@"%@",[_emailarray objectatindex:i]] utf8string],-1, null);          sqlite3_bind_text(stmt, 5,[[nsstring stringwithformat:@"%@",@"no image"] utf8string],-1, null);                 if ((x = sqlite3_step(stmt)) != sqlite_done) {             nslog(@"%s: step failed: %s (%d)", __function__, sqlite3_errmsg(database1), x);         }          sqlite3_reset(stmt);     }       sqlite3_finalize(stmt);        nslog(@"contentstring%@",contentstring);      if([contentstring length] != 0){          uialertview *alertforaddressbook=[[uialertview alloc] initwithtitle:@"friends added addressbook:"  message:contentstring delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil];         [alertforaddressbook show];        // [alertforaddressbook release];         //[contentstring release];      }      } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -