コード例 #1
0
ファイル: IPhonePIM.cs プロジェクト: lsp1357/appverse-mobile
        /// <summary>
        /// 
        /// </summary>
        /// <param name="person">
        /// A <see cref="ABPerson"/>
        /// </param>
        /// <returns>
        /// A <see cref="ContactAddress[]"/>
        /// </returns>
        private ContactAddress[] GetContactAdresses(ABPerson person)
        {
            List<ContactAddress> contactAddressList = new List<ContactAddress>();

            if(person != null) {
                ABMultiValue<PersonAddress> addresses = person.GetAllAddresses();
                if(addresses!=null) {

                    IEnumerator enumerator = addresses.GetEnumerator();
                    while(enumerator.MoveNext()){
                        object currentAddress = enumerator.Current;
                        string label = ((ABMultiValueEntry<PersonAddress>)currentAddress).Label;
                        PersonAddress personAddress = ((ABMultiValueEntry<PersonAddress>)currentAddress).Value;

                        ContactAddress contactAddress = new ContactAddress();

                        if(label == ABLabel.Home) {
                            contactAddress.Type = DispositionType.HomeOffice;
                        } else if(label == ABLabel.Work) {
                            contactAddress.Type = DispositionType.Work;
                        } else if (label == ABLabel.Other) {
                            contactAddress.Type = DispositionType.Other;
                        }

                        /* old API
                        NSObject[] keys = addressDictionary.Keys;

                        foreach(NSObject key in keys) {
                            NSObject currentValue = addressDictionary.ObjectForKey(key);
                            if(currentValue != null) {
                                if(key.ToString() == ABPersonAddressKey.Street) {
                                    contactAddress.Address = currentValue.ToString();
                                    // contactAddress.AddressNumber = NOT PROVIDED BY API
                                }

                                if(key.ToString() == ABPersonAddressKey.City) {
                                    contactAddress.City = currentValue.ToString();
                                }
                                if(key.ToString() == ABPersonAddressKey.Country) {
                                    contactAddress.Country = currentValue.ToString();
                                }
                                if(key.ToString() == ABPersonAddressKey.Zip) {
                                    contactAddress.PostCode = currentValue.ToString();
                                }
                            }
                        }
                        */
                        contactAddress.Address =  personAddress.Street;
                        contactAddress.City = personAddress.City;
                        contactAddress.Country = personAddress.Country;
                        contactAddress.PostCode = personAddress.Zip;

                        contactAddressList.Add(contactAddress);
                    }
                }
            }
            return contactAddressList.ToArray();
        }
コード例 #2
0
ファイル: IPhonePIM.cs プロジェクト: lsp1357/appverse-mobile
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contactAddressList">
        /// A <see cref="ContactAddress[]"/>
        /// </param>
        /// <returns>
        /// A <see cref="ABMultiValue<NSDictionary>"/>
        /// </returns>
        private ABMultiValue<NSDictionary> ConvertContactAddressesToNative(ContactAddress[] contactAddressList)
        {
            ABMutableDictionaryMultiValue multableMultilabel = new ABMutableDictionaryMultiValue();

            if(contactAddressList!=null) {
                foreach(ContactAddress contactAddress in contactAddressList) {

                    NSString label = ABLabel.Other; // default is "Other"
                    if(contactAddress.Type == DispositionType.HomeOffice) {
                        label = ABLabel.Home;
                    } else if(contactAddress.Type == DispositionType.Work) {
                        label = ABLabel.Work;
                    }

                    NSMutableDictionary addressDictionary = new NSMutableDictionary();
                    if(contactAddress.Address != null) {
                        string address = contactAddress.Address;
                        if(contactAddress.AddressNumber != null) {
                            address += " " + contactAddress.AddressNumber;
                        }
                        addressDictionary.Add(ABPersonAddressKey.Street,new NSString(address));
                    }

                    if(contactAddress.City != null) {
                        addressDictionary.Add(ABPersonAddressKey.City,new NSString(contactAddress.City));
                    }

                    if(contactAddress.Country != null) {
                        addressDictionary.Add(ABPersonAddressKey.Country,new NSString(contactAddress.Country));
                    }

                    if(contactAddress.PostCode != null) {
                        addressDictionary.Add(ABPersonAddressKey.Zip,new NSString(contactAddress.PostCode));
                    }

                    multableMultilabel.Add(addressDictionary, label);
                }
            }

            return multableMultilabel;
        }