Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
多值url地址簿iphone_Iphone_Objective C_Ios_Xcode_Ios6 - Fatal编程技术网

多值url地址簿iphone

多值url地址簿iphone,iphone,objective-c,ios,xcode,ios6,Iphone,Objective C,Ios,Xcode,Ios6,我想在通讯簿中创建一个新联系人。 当您想存储更多URL(某些社交网络的网址)时,就会出现问题。 我的代码在iOS6模拟器中工作得非常好。但在真正的iPhone中,iOS6存储了所有的值​​除了网址。 我已经找了几天了,找不到解决办法,如果有人能帮忙,我将非常感激 我的代码: -(void) addContactToAddressBook:(ABAddressBookRef) iPhoneAddressBook { CFErrorRef error = NULL; ABRec

我想在通讯簿中创建一个新联系人。 当您想存储更多URL(某些社交网络的网址)时,就会出现问题。 我的代码在iOS6模拟器中工作得非常好。但在真正的iPhone中,iOS6存储了所有的值​​除了网址。 我已经找了几天了,找不到解决办法,如果有人能帮忙,我将非常感激

我的代码:

-(void) addContactToAddressBook:(ABAddressBookRef) iPhoneAddressBook 
{

    CFErrorRef error = NULL;

    ABRecordRef newPerson = ABPersonCreate();

    //Name and phone number
    ABRecordSetValue(newPerson, kABPersonFirstNameProperty, (__bridge CFStringRef)_nameField.text, &error);
    ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFStringRef)_phoneField.text, kABPersonPhoneMainLabel, NULL);
    ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);

    //Email value
    ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(emailMultiValue, (__bridge CFStringRef)_emailField.text, kABWorkLabel, NULL);
    ABRecordSetValue(newPerson, kABPersonEmailProperty, emailMultiValue, nil);
    CFRelease(emailMultiValue);

    //URL values
    ABMutableMultiValueRef urlMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef)_FacebookField.text, (CFStringRef)@"Facebook", NULL);
    ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef)_twitterField.text, (CFStringRef)@"Twitter", NULL);
    ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef)_linkedinField.text, (CFStringRef)@"Linkedin", NULL);
    ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef)_googleField.text, (CFStringRef)@"Google+", NULL);
    ABRecordSetValue(newPerson, kABPersonURLProperty, urlMultiValue, nil);
    CFRelease(urlMultiValue);

    ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);

    ABAddressBookSave(iPhoneAddressBook, &error);
    if (error != NULL)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Contact not saved" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
        [alert show];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Contact saved" message:@"Your contact was successfully saved" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    }
}

谢谢

>根据苹果网站上的文档(向下滚动到页面中间的隐私),访问该地址簿必须先经过编程才能访问。这就是我最后要做的

-(void)requestPermission
{
        ABAddressBookRef iPhoneAddressBook = ABAddressBookCreateWithOptions(NULL, NULL);

        if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
            ABAddressBookRequestAccessWithCompletion(iPhoneAddressBook, ^(bool granted, CFErrorRef error) {
                if (granted) {
                    // First time access has been granted, add the contact
                    [self addContactToAddressBook:iPhoneAddressBook];
                } else {
                    // User denied access
                    // Display an alert telling user the contact could not be added
                }
            });
        }
        else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
            // The user has previously given access, add the contact
            [self addContactToAddressBook:iPhoneAddressBook];
        }
        else {
            // The user has previously denied access
            // Send an alert telling user to change privacy setting in settings app
        }

    }

-(void)addContactToAddressBook:(ABAddressBookRef)iPhoneAddressBook
{
    CFErrorRef error = NULL;
    ABRecordRef newPerson = ABPersonCreate();

    //Name and phone number
    ABRecordSetValue(newPerson, kABPersonFirstNameProperty, (__bridge CFStringRef)_nameField.text, &error);
    ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(multiPhone, (__bridge CFStringRef)_phoneField.text, kABPersonPhoneMainLabel, NULL);
    ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
    CFRelease(multiPhone);

    //Email value
    ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(emailMultiValue, (__bridge CFStringRef)_emailField.text, kABWorkLabel, NULL);
    ABRecordSetValue(newPerson, kABPersonEmailProperty, emailMultiValue, nil);
    CFRelease(emailMultiValue);

    //URL values
    ABMutableMultiValueRef urlMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
    ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef)_FacebookField.text, (CFStringRef)@"Facebook", NULL);
    ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef)_twitterField.text, (CFStringRef)@"Twitter", NULL);
    ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef)_linkedinField.text, (CFStringRef)@"Linkedin", NULL);
    ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef)_googleField.text, (CFStringRef)@"Google+", NULL);
    ABRecordSetValue(newPerson, kABPersonURLProperty, urlMultiValue, nil);
    CFRelease(urlMultiValue);

    // ...
    // Set other properties
    // ...
    ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);

    ABAddressBookSave(iPhoneAddressBook, &error);
    CFRelease(newPerson);
    CFRelease(iPhoneAddressBook);
    if (error != NULL)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Contact not saved" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
        [alert show];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Contact saved" message:@"Your contact was successfully saved" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    }
}

有人能帮我吗?我找不到解决办法。。。。谢谢