I want to get the name of all the Exchange sources that my iPhone is synced to. For e.g. if I sync my device to Gmail and Hotmail accounts using ActiveSync Exchange, in the native contacts, I can see different sections based on the different accounts that I have setup. When I try to programmatically do the same, the only information I get is sourceType (which is Exchange in both cases) and sourceName (which is "Contacts" in both cases). There's no way for me to differentiate which is the Gmail "Contacts" and which is the Hotmail "Contacts".
Anyone know how to do this? Here's my code:
CFArrayRef allSources = ABAddressBookCopyArrayOfAllSources(book);
for (CFIndex i = 0; i < CFArrayGetCount(allSources); i++) {
ABRecordRef source = (ABRecordRef)CFArrayGetValueAtIndex(allSources, i);
NSString *sourceTypeName = (NSString *)((CFStringRef)ABRecordCopyValue(source, kABSourceNameProperty));
NSLog(#"%#", sourceTypeName);
}
You can't do this in iOS it seems (yet)
Related
I am half way doing chat using XMPP. I have registered and logged in to ejabberd server.
I can see in web interface that there are 10 registered users and 4 online users. But Roster delegates not getting any contacts.
I have tried this solution. I did not get any results.
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
NSXMLElement *queryElement = [iq elementForName: #"query" xmlns: #"jabber:iq:roster"];
if (queryElement) {
NSArray *itemElements = [queryElement elementsForName: #"item"];
[ArrayUsers removeAllObjects];
for (int i=0; i<[itemElements count]; i++) {
NSString *jid=[[[itemElements objectAtIndex:i] attributeForName:#"jid"] stringValue];
[ArrayUsers addObject:jid];
}
}
return NO;
}
What may be the issue ? Do I have to configure the server settings for this to get contacts. It will be accessible to all by default?
Or, do i have to make a query to get the user details and automatically synced to CoreData storage.
Any help will be much appreciated.
The issue was that the shared roster module was not enabled in ejabberd configuration file. You can just enable mod_shared_roster in your ejabberd config modules section (the people who know how to do will understand. I personally dont know! So seeked help from others in the company).
Then, the shared Roster option will be available in the web interface of the admin side of ejabberd server.
Now configure the server to see all users to be seen for every body using the following link:
ejabbered configuration
Now, if you have logged in and set for automatic sync of Roster (XMMP framework by RobbieHanson Eg), you will get all users in the list.
Create a Shared Roster and get all users from the Roster. Check this
When I scroll My Contacts App to the bottom, where it shows the number of contacts, It says 2568 contacts.
But in my app when I try to fetch the number of contacts from AddressBook, by ABAddressBookGetPersonCount, I get 2582 contacts.
Has Anyone noticed this? Why is this difference there? Does the AddressBook framework give me wrong information??
EDIT
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSLog(#"num people to send: %ld", nPeople);
NSLog(#"num people in array: %ld", CFArrayGetCount(allPeople));
These two logs, give me the same number, however this number is different from that written at the bottom of the contacts app in iphone.
The contacts app pulls in its contacts from various groups. You can change the number of people in your list by going to the groups select page (top left in IOS 7) and selecting or deselecting your contacts.
If your list is pulling in all the contacts 'available' to you, the difference is due to contacts coming from a source not used in the Contacts App. You may have noticed that you can start to type in an email and it will auto fill the email even though you have no contact for that person. That information is stored inside the AddressBook database, but is not pulled into the Contact App. When you use the ABAddressBookCopyArrayOfAllPeople, it also pulls in these 'contacts'. You can verify this by putting all the contact's in a tableview and printing out the name, first email, first phone number, for each of the contacts. You will probably find a few contacts which only contain an email address (or possibly phone number).
An example of how to print off all the contacts can be found here.
Use this code
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
CFArrayRef allPeople = (ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByFirstName));
//CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
CFIndex nPeople = CFArrayGetCount(allPeople); // bugfix who synced contacts with facebook
These days ,I am working a mail client by using the mailcore.Everytime, Successfully connected to the imap server,but I can't get the INBOX list.The key code
CTCoreFolder *inbox = [account folderWithPath:#"INBOX"];
NSArray *messageList = [inbox messagesFromSequenceNumber :1 to:0 withFetchAttributes:CTFetchAttrEnvelope];
NSLog(#"%d",[messageList count]);
Evertime ,the output is 0;I do this is wrong ?
Why not to use Address Book API ?
Here are some answers:
iOS how to get Email contacts from Mails app?
Get all E-Mail addresses from contacts (iOS)
I am using the following code to retrieve the email addresses of persons picked by the user
ABMultiValueRef emailMultiValue = ABRecordCopyValue(person, kABPersonEmailProperty);
NSArray *emailAddresses = (__bridge NSArray*)ABMultiValueCopyArrayOfAllValues(emailMultiValue);
Everything has worked fine since iOS6 and Facebook integration came. When I choose a contact that is not linked to a Facebook account (this means that I'm not friend on FB with this contact) everything works fine and I retrieve 2 email addresses (work and home).
But when I select a contact that is linked to me via Facebook (this contact has also a home and work email address plus the Facebook email address in the contact browser) the emailAddresses array is nil.
Does anyone had this problem before or has any hints on this?
Thanks in advance!
To filter out the Facebook contacts, you can check the kABSourceTypeProperty of the person. If it returns kABSourceTypeCardDAV, it may be from Facebook, but it most certainly not a local contact (which would return kABSourceTypeLocal).
Unfortunately, as of iOS 6, there is not a Facebook specific source type, so using kABSourceTypeCardDAV may filter out other sources that you may actually care about. In any case, here is some code;
ABRecordRef source = ABPersonCopySource(person);
NSNumber *sourceTypeRef = (__bridge NSNumber *)((CFNumberRef)ABRecordCopyValue(source, kABSourceTypeProperty)
if ([sourceTypeRef intValue] == kABSourceTypeCardDAV)
; // this is probably, maybe, could be a Facebook contact
if ([sourceTypeRef intValue] == kABSourceTypeLocal)
; // this is definitely a local contact
if ([sourceTypeRef intValue] == kABSourceTypeExchange)
; // this is from an exchange server
// etc...
I sortof found a way to check if a person is a facebook contact. In my case the problem was that facebook contacts are not editable, so I didnt want to show them in the "addressbook updater" function Im making.
(in the addressbook app from apple, you can edit facebook contacts, but what the app actually does is to create a new contact with the new information and links it to the facebook contact. I couldnt do this, because linking is not an public API in iOS.)
So to find those facebook contacts that I want to ignore, I just check if ABRecordSetValue returns true when I set the firstname to the current firstname, like this.
bool didset = ABRecordSetValue(person, kABPersonFirstNameProperty, ABRecordCopyValue(person, kABPersonFirstNameProperty), nil);
I found out that since iOS6 there are linked contacts (normal contact <-> facebook <-> twitter and so on...).
In order to get all emails of all linked contacts, the following post helped me:
iOS 6 address book empty kABPersonPhoneProperty
Hope it helps!
In my application, if the user gave their gmail account then i am required to open the mail client with the gmail login credentials which comes when we select gmail option of mail programmatically but if that account is already stored in mail then i am required to redirect the user directly to their account. Can anybody pliz give me a glimpse of how i can achieve this programmatically.
You won't get that much control over the Mail app as all apps on the iPhone are sandboxed to prevent them from messing with Apple applications.
The only thing you can do (if you want to open the mail client to send an email), is something like this:
/* create mail subject */
NSString *subject = [NSString stringWithFormat:#"Subject"];
/* define email address */
NSString *mail = [NSString stringWithFormat:#"test#test.com"];
/* define allowed character set */
NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
/* create the URL */
NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:#"mailto:?to=%#&subject=%#",
[mail stringByAddingPercentEncodingWithAllowedCharacters:set],
[subject stringByAddingPercentEncodingWithAllowedCharacters:set]]];
/* load the URL */
[[UIApplication sharedApplication] openURL:url];
/* release the URL. If you are using ARC, remove this line. */
[url release];
Swift version of Léon Rodenburg's answer:
// define email address
let address = "test#test.com"
// create mail subject
let subject = "Subject"
// create the URL
let url = NSURL(string: "mailto:?to=\(address)&subject=\(subject)".stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!)
// load the URL
UIApplication.sharedApplication().openURL(url!)
Swift:
if let url = NSURL(string: "mailto://\(email)") {
UIApplication.sharedApplication().openURL(url)
}
I would suggest a much more improved answer.
The Slack.com mobile app does this, it detects common email clients listed on the device and shows a popup picker of 'which' email client you would like to open.
So to implement:
Google around to find the top 10 email clients (eg Mail, Google Inbox, OutLook, AirMail etc).
Get a list of installed apps on the phone either by searching all apps (but I am told you can now only find if an app is explicitly installed, so you will need detect the app).
Show a popup list if more than 1 email app is detected, requesting them 'which' app to open eg. Mail, Inbox.
This is the best solution I have seen working to date.