Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Button “将联系人添加到通讯簿”按钮_Button_Contact_Addressbook - Fatal编程技术网

Button “将联系人添加到通讯簿”按钮

Button “将联系人添加到通讯簿”按钮,button,contact,addressbook,Button,Contact,Addressbook,我正在IOS中使用和应用程序,我想添加一个按钮,当人们点击它时,它会自动将联系人(姓名、号码和图片)添加到手机联系人列表中 联系人姓名为Clinica Lo Curro,电话号码为6003667800 有人能帮我查一下密码吗 问候, Eugenio Durán从构建阶段添加AddressBook.framework和AddressBookUI.framework,将二进制文件与库链接起来。 并将AddressBookUI导入头文件,如下所示 #import <AddressBookUI/A

我正在IOS中使用和应用程序,我想添加一个按钮,当人们点击它时,它会自动将联系人(姓名、号码和图片)添加到手机联系人列表中

联系人姓名为Clinica Lo Curro,电话号码为6003667800

有人能帮我查一下密码吗

问候,


Eugenio Durán

从构建阶段添加AddressBook.framework和AddressBookUI.framework,将二进制文件与库链接起来。 并将AddressBookUI导入头文件,如下所示

#import <AddressBookUI/AddressBookUI.h>

为您复制粘贴代码。。
-(IBAction)addContact:(id)sender
{
    ABPeoplePickerNavigationController *peoplePicker=[[ABPeoplePickerNavigationController alloc] init];
    ABAddressBookRef addressBook = [peoplePicker addressBook];

    // create person record

    ABRecordRef person = ABPersonCreate();
    // set name and other string values

    UIImage *personImage = [UIImage imageNamed:@"cinema.png"];
    NSData *dataRef = UIImagePNGRepresentation(personImage);

    NSString *firstName=@"AKASH";
    NSString *lastName=@"MALHOTRA";

    NSString *organization=@"Aua Comp Pvt Ltd.";
    NSString *jobTitle=@"iPhone App Developer";
    NSString *departMent=@"Mobile Division";
    NSString *webURL=@"http://www.google.com";
    NSString *personEmail=@"goel.anjan@gmail.com";
    NSString *phoneNo=@"9856756445 or 7656876765 or 8976566775";
    NSString *personNote=@"I am just a kid";

    NSString *addressOne=@"HN-23,Sector-2,Chandigarh";
    NSString *addressTwo=@"AL-19,Sector-5,SaltLake";

    NSString *cityName=@"Kolkata";
    NSString *stateName=@"West Bengal";
    NSString *pinCode=@"700091";
    NSString *country=@"India";

    CFErrorRef cfError=nil;


    ABRecordSetValue(person, kABPersonOrganizationProperty, (__bridge CFStringRef)organization, NULL);

    if (firstName) {
        ABRecordSetValue(person, kABPersonFirstNameProperty, (__bridge CFTypeRef)(firstName) , nil);
    }

    if (lastName) {
        ABRecordSetValue(person, kABPersonLastNameProperty, (__bridge CFTypeRef)(lastName) , nil);
    }

    if (jobTitle) {
        ABRecordSetValue(person, kABPersonJobTitleProperty,(__bridge CFTypeRef)(jobTitle), nil);
    }

    if (departMent) {
        ABRecordSetValue(person, kABPersonDepartmentProperty,(__bridge CFTypeRef)(departMent), nil);
    }

    if (personNote) {
        ABRecordSetValue(person, kABPersonNoteProperty, (__bridge CFTypeRef)(personNote), nil);
    }

    if (dataRef) {
        ABPersonSetImageData(person, (__bridge CFDataRef)dataRef,&cfError);
    }


    if (webURL)
    {
        ABMutableMultiValueRef urlMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
        ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef) webURL, kABPersonHomePageLabel, NULL);
        ABRecordSetValue(person, kABPersonURLProperty, urlMultiValue, nil);
        CFRelease(urlMultiValue);
    }

    if (personEmail)
    {
        ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
        ABMultiValueAddValueAndLabel(emailMultiValue, (__bridge CFStringRef) personEmail, kABWorkLabel, NULL);
        ABRecordSetValue(person, kABPersonEmailProperty, emailMultiValue, nil);
        CFRelease(emailMultiValue);
    }

    if (phoneNo)
    {
        ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
        NSArray *venuePhoneNumbers = [phoneNo componentsSeparatedByString:@" or "];
        for (NSString *venuePhoneNumberString in venuePhoneNumbers)
            ABMultiValueAddValueAndLabel(phoneNumberMultiValue, (__bridge CFStringRef) venuePhoneNumberString, kABPersonPhoneMainLabel, NULL);
        ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
        CFRelease(phoneNumberMultiValue);
    }

    // add address

    ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
    NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];

    if (addressOne)
    {
        if (addressTwo)
            addressDictionary[(NSString *) kABPersonAddressStreetKey] = [NSString stringWithFormat:@"%@\n%@", addressOne, addressTwo];
        else
            addressDictionary[(NSString *) kABPersonAddressStreetKey] = addressOne;
    }

    if (cityName)
        addressDictionary[(NSString *)kABPersonAddressCityKey] = cityName;
    if (stateName)
        addressDictionary[(NSString *)kABPersonAddressStateKey] = stateName;
    if (pinCode)
        addressDictionary[(NSString *)kABPersonAddressZIPKey] = pinCode;
    if (country)
        addressDictionary[(NSString *)kABPersonAddressCountryKey] = country;

    ABMultiValueAddValueAndLabel(multiAddress, (__bridge CFDictionaryRef) addressDictionary, kABWorkLabel, NULL);
    ABRecordSetValue(person, kABPersonAddressProperty, multiAddress, NULL);
    CFRelease(multiAddress);


    //Add person Object to addressbook Object.
    ABAddressBookAddRecord(addressBook, person, &cfError);

    if (ABAddressBookSave(addressBook, nil)) {
        NSLog(@"\nPerson Saved successfuly");
    } else {
        NSLog(@"\n Error Saving person to AddressBook");
    }
}