0

[__NSCFString timeIntervalSinceReferenceDate]:无法识别的选择器发送到实例 0x6c2ccb0

当我尝试在通讯录中添加联系人时,我的代码中出现此错误。欣赏任何解决方案

     NSArray *names=[test componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
        NSLog(@"Count:%d,%d",[names count],[test length],[names objectAtIndex:0],[names objectAtIndex:1] );
        //Works fine, a sample output-> For String:John Smith ; Count:2,10,John,Smith

        //CFStringRef temp; //for troubleshooting

    switch([names count])
    {
     case 1:ABRecordSetValue(self.person12,kABPersonFirstNameProperty,(__bridge_retained CFTypeRef)([names objectAtIndex:0]), NULL);
                                break;
     case 2: // Error occurs in case 2 as count is 2
     {

      //Commented region is what I tried out as an alternative but didnt work
     /*temp=(__bridge_retained CFTypeRef)((NSString*)[names objectAtIndex:0]);
                                ABRecordSetValue(self.person12,kABPersonFirstNameProperty,(CFTypeRef)temp,NULL);

    temp=(__bridge_retained CFStringRef)((NSString*)[[names objectAtIndex:1] substringToIndex:[[names objectAtIndex:1] length]-1]);
                               ABRecordSetValue(self.person12,kABPersonLastNameProperty,temp,NULL);*/

ABRecordSetValue(self.person12,kABPersonFirstNameProperty,(__bridge CFTypeRef)([names objectAtIndex:0]),NULL);// Error occurs after the execution of breakpoint here

ABRecordSetValue(self.person12,kABPersonLastNameProperty,(__bridge CFTypeRef)([[names objectAtIndex:1] substringToIndex:[[names objectAtIndex:1] length]-1]),NULL);
     break;
      }



    default:
       {
    ABRecordSetValue(self.person12,kABPersonFirstNameProperty,(__bridge_retained CFTypeRef)([names objectAtIndex:0]),NULL);
                                ABRecordSetValue(self.person12,kABPersonMiddleNameProperty,(__bridge_retained CFTypeRef)([names objectAtIndex:1]),NULL);
                                test=@"";
         for(int j=2;j<[names count];j++)
              test=[test stringByAppendingString:[names objectAtIndex:j]];

        test=[test substringToIndex:[test length]- 1];
                                ABRecordSetValue(self.person12,kABPersonLastNameProperty,(__bridge_retained CFTypeRef)test,NULL);
         break;
       }
     }
4

1 回答 1

0

初始化 ABRecordRef
即,

self.person12=ABPersonCreate();

初始化通讯录

self.addressBook=ABAddressBookCreate();

这将解决问题!

于 2013-08-12T09:36:06.800 回答