Пример #1
0
partial         void AddElba(Id sender)
        {
            NSMutableDictionary homeAddr, workAddr;
            ABMutableMultiValue multiValue;

            // Get the address book - there is only one.
            ABAddressBook ab = ABAddressBook.SharedAddressBook;

            // Create a record.
            ABPerson person = new ABPerson();

            // Set value in record for first name property.
            person.SetValueForProperty((NSString) "Able", AddressBookFramework.kABFirstNameProperty);
            // Set value in record for last name property.
            person.SetValueForProperty((NSString) "Elba", AddressBookFramework.kABLastNameProperty);

            // kABAddressProperty is a multiValue.
            // It's values, such as kABAddressHomeLabel, have in turn keys,
            // such as kABAddressStreetKey.
            // Create and populate a NSDictionary with some kABAddressHomeLabel keys.
            homeAddr = new NSMutableDictionary();
            homeAddr[AddressBookFramework.kABAddressStreetKey] = (NSString) "123 Home Dr.";
            homeAddr[AddressBookFramework.kABAddressCityKey] = (NSString) "Home City";
            homeAddr[AddressBookFramework.kABAddressStateKey] = (NSString) "CA";
            homeAddr[AddressBookFramework.kABAddressZIPKey] = (NSString) "94110";
            homeAddr[AddressBookFramework.kABAddressCountryKey] = (NSString) "United States";

            // Create and populate a NSDictionary with some kABAddressWorkLabel keys.
            workAddr = new NSMutableDictionary();
            workAddr[AddressBookFramework.kABAddressStreetKey] = (NSString) "123 Home Dr.";
            workAddr[AddressBookFramework.kABAddressCityKey] = (NSString) "Home City";
            workAddr[AddressBookFramework.kABAddressStateKey] = (NSString) "CA";
            workAddr[AddressBookFramework.kABAddressZIPKey] = (NSString) "94110";
            workAddr[AddressBookFramework.kABAddressCountryKey] = (NSString) "United States";

            // Create an ABMultivalue and add the kABAddressHomeLabel and
            // kABAddressWorkLabel NSDictionaries
            multiValue = new ABMutableMultiValue();
            multiValue.AddValueWithLabel(homeAddr, AddressBookFramework.kABAddressHomeLabel);
            multiValue.AddValueWithLabel(workAddr, AddressBookFramework.kABAddressWorkLabel);

            // Set value in record for kABAddressProperty.
            person.SetValueForProperty(multiValue, AddressBookFramework.kABAddressProperty);
            multiValue.Release();

            // kABPhoneProperty is a multivalue.
            // Create and populate a multiValue.
            multiValue = new ABMutableMultiValue();
            multiValue.AddValueWithLabel((NSString) "408-974-0000", AddressBookFramework.kABPhoneWorkLabel);
            multiValue.AddValueWithLabel((NSString) "408-974-1111", AddressBookFramework.kABPhoneHomeLabel);
            multiValue.AddValueWithLabel((NSString) "408-974-2222", AddressBookFramework.kABPhoneMobileLabel);
            multiValue.AddValueWithLabel((NSString) "408-974-3333", AddressBookFramework.kABPhoneMainLabel);
            multiValue.AddValueWithLabel((NSString) "408-974-4444", AddressBookFramework.kABPhoneHomeFAXLabel);
            multiValue.AddValueWithLabel((NSString) "408-974-5555", AddressBookFramework.kABPhoneWorkFAXLabel);
            multiValue.AddValueWithLabel((NSString) "408-974-6666", AddressBookFramework.kABPhonePagerLabel);

            // Set value in record for kABPhoneProperty.
            person.SetValueForProperty(multiValue, AddressBookFramework.kABPhoneProperty);
            multiValue.Release();

            // Add record to the Address Book
            if (ab.AddRecord(person))
            {
                // Save the Address Book
                if (ab.Save())
                {
                    Console.WriteLine("Success");
                }
            }
            person.Release();
        }