如何允许我的应用访问iphone联系人并存储它们以便在应用中使用

时间:2012-11-06 04:55:09

标签: iphone flash

嘿所以我正在制作一个应用程序,并想知道如何能够访问iPhone的联系人并点击你想要的电话号码,他们将被存储使用。

更新-----

我是Adobe Flash CS5.5的开发者

1 个答案:

答案 0 :(得分:0)

您需要包含AddressBook.framework我也使用MContact课程来使用联系人姓名,号码等。

#import <AddressBook/AddressBook.h>
#import <AddressBook/ABAddressBook.h>
#import <AddressBook/ABPerson.h>

[contactList removeAllObjects];

// open the default address book. 
ABAddressBookRef m_addressbook = ABAddressBookCreate();
if (!m_addressbook) {
    NSLog(@"opening address book");
}

// can be cast to NSArray, toll-free
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

// CFStrings can be cast to NSString!

for (int i=0;i < nPeople;i++) { 
 MContact *contact = [[MContact alloc] init];

 ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
 CFStringRef firstName, lastName;
 firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
 lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty);
 contact.name = [NSString stringWithFormat:@"%@ %@", firstName, lastName];

 ABMutableMultiValueRef eMail  = ABRecordCopyValue(ref, kABPersonEmailProperty);
 if(ABMultiValueGetCount(eMail) > 0) {
  contact.email =  (NSString *)ABMultiValueCopyValueAtIndex(eMail, 0);
  [contactList addObject:contact];
 }

 CFRelease(ref);
 CFRelease(firstName);
 CFRelease(lastName);


}

////and here MContact is NObject (Bean) file bellow

@interface MContact : NSObject { 
NSString *email; 
NSString *name; 
NSString *lastName; 
NSString *phone; 

BOOL isSelected; 
} 
@property (nonatomic, retain) NSString *email; 
@property (nonatomic, retain) NSString *name; 
@property (nonatomic, retain) NSString *lastName; 
@property (nonatomic, retain) NSString *phone; 

@property (nonatomic) BOOL isSelected; 
@property (nonatomic, readonly) NSString *displayName; 
@end