Does iOS have a standard way to enter and store a street address? - ios

I'd like to prompt for a street address, in exactly the same way as the Contacts app.
I could mimic its UI, but that would involve duplicating a lot of existing functionality; the country list, the way it re-configures based on the country selection, validation, formatting, localization, etc. Is there an existing framework that provides this?
I'm also storing the entered value in Core Data, which of course doesn't have an Address type. Is it preferable to store the fields individually, use Transformable, or just use a plain string? Is there an existing class that I could re-use/subclass for this?
I can assume that iOS 5 is required.

No it doesn't, unfortunately. There are a few projects that help with this, though. You might find my project QuickDialog useful for this: QuickDialog

This is as good as I know of, but may not meet your needs. From The Address Book Programming Guide:
The Address Book UI framework provides four controllers:
ABPeoplePickerNavigationController prompts the user to select a person record from their address book.
ABPersonViewController displays a person record to the user and optionally allows editing.
ABNewPersonViewController prompts the user create a new person record.
ABUnknownPersonViewController prompts the user to complete a partial person record, optionally allows them to add it to the address book.

Related

iOS Address book records existing outside of address book database

I was reviewing Address Book Programming Guide for iOS and came across this comment:
Even though records are usually part of the Address Book database, they can also exist outside of it. This makes them a useful way to store contact information your application is working with.
What does this mean? Can I create contacts that are viewable by contacts app but not stored in the shared database?
Thanks!
A Record is just an object, so you can create one and do whatever you want with it. That statement means you can create and use an ABRecord for your own purposes without putting it into the Address Book database.
It means the opposite of what you asked - if you want a contact viewable in the contacts app, you have to put it in the Address Book database. However, if you're going to make your own contacts app (or add your own internal address book functionality), you could create and use ABRecords in your implementation.
ABRecordRef aRecord = ABPersonCreate(); will create a new record, and you can fill it out with contact information and use it internally in your app. Thus, as the snippet you found said, you can use them as a way to store contact information within your app without putting those contacts into the address book database.

How can I check if a person has been selected from the Address Book before in iOS?

I am building an app that relies on choosing people from the address book, and adding their information to an NSMutableArray. I only want each person chosen once, so I want the ability to grey out the people who have already been chosen. I am not sure where to look. Can someone point me in the right direction?
You should keep a list of already chosen users. For example, you can save them into CoreData store, SQLite table, plist file, etc. To compare currently selected user with those who are already on the list you'll need some unique identifier for every user. In most cases it's enough to store user's ID on the list, not the whole entity.

ABPersonViewController without access to the addressbook

I am implementing an application in which the user should be able to import a contact from the address book or to provide a contact themselves.
I implemented everything using https://github.com/soffes/sspersonviewcontroller .
New contacts are added to the address book and everything works really well.
I had all the fields and editing capabilities by using ABPersonViewController etc ...
BUT now the client insists that the contact should NOT be stored in the addressbook but in the application and that the user should NEVER be asked to grant access to the address book with the exception of the import.
I got the "import contact into app" working by using a serializer for an ABRecordRef (from https://github.com/nvrooij/Let-s-Share/blob/master/Classes/ABRecordSerializer.h )
But my biggest problem is, that ABNewPersonViewController and ABPersonViewController insist on asking the user for access to the addressbook.
So what i need:
A view to create a contact without access to the address book. It should return a ABRecordRef to a person so i could serialize it somewhere (atm i store it to NSUserDefaults)
A view to edit a contact without access to the address book.
What i already tried:
Following How to Use a ABPersonViewController without connecting to AddressBook i set the displayedPerson - but the "grant access popup" still shows up.
From the docs of ABNewPersonViewController and ABPersonViewController i got the impression that subclassing and overriding the getter for the addressbook to return nil in all cases would work and i would wind up with view which has no address book.
But somewhere in there (i assume the view itself) the addressbook is created again and i can't get rid of this call.
How you can help_
Any pointers to a re-implementation of ABPersonViewController (including editing capabilities) or any other hints are very welcome.
Any ideas of how to get a create user viewcontroller with all the nice things (country selection, field additions etc) are also highly welcome.
If you think my approach is completely off please also comment. I am always looking for different angles and might have dug too deep into this whole address book disaster.
I wish the controllers for creating and editing contacts would be completely decoupled from the address book and would return a ABRecordRef instead of accessing the addressbook. In my case it would highly simplify my task (a man can dream).
All the best,
iosGoblin
I solved/circumvented the problem as follows:
I dropped editing capabilities and I created a view controller which resembles ABNewPersonViewController (only some specific fields like name, surename, phone number, address).
From the input i creata a ABRecordRef (helpful code at http://www.modelmetrics.com/tomgersic/iphone-programming-adding-a-contact-to-the-iphone-address-book/ ).
I serialize this contact into NSUserDefaults using the ABRecordSerializer (link in my question)
If the user imports a contact I just serialize the contact i get back from the ABPeoplePickerNavigationController into NSUserDefaults.
If a contact is stored in NSUserDefaults I deserialize and display it.
Recap:
I reimplemented reduced version of ABNewPersonViewController
I use a serializer (link above) to store a contact in NSUserDefaults (either from my view controller or from a imported one, once it's serialized i don't care anymore)
I desirialize the contact and display it
All the best,
iosGoblin

IOS: Can I use ABAddressBook to store contact information outside the iPhones Contacts?

I'm wanting to store some contact information and allow the user to call/email the person instead of just looking up the info. I don't want the contacts stored in the user's Address Book in their contacts though. I want to keep it within the app only. Can I use ABAddressBook for this or do I need to create my own classes to accomplish this?
I'll address both your questions:
Can I use ABAddressBook for this?
You cannot use ABAddressBook to store a separate contacts database. Here's an excerpt from the ABAddressBook Class Reference:
The ABAddressBook class provides a programming interface to the Address Book—a centralized database used by multiple applications to store contact and other personal information about people.
The database referred to here is a pre-specified database; there is no method or class to create a new one, as the whole Address Book framework provides access to a single database accessible to the user through the Contacts application.
Do I need to create my own classes to accomplish this?
You would need to create a custom class for this. If you plan on supporting users with many, many contacts (in the thousands/high hundreds range), you probably would use an SQLite database. If you plan on supporting users with few contacts, you should probably use a .plist.
Usually, Objective-C programmers use the C library for SQLite directly, but now there is a great wrapper that you can find here called FMDB.
For info on the syntax and basics of SQLite, see the SQLite Language Guide.
Lastly, here are a couple books on SQLite and database programming for iOS:
(Apress) Using SQLite
(Wrox) Professional iPhone and iPad Database Application Programming
Hope this helps!

iOS address book read only concept

Is there any concept in the address book API of inserting a read-only or locked entry from an application? We want to integrate with the Address book, but don't want the entries to be removed.
Thanks in advance!
Rob
The Address Book belongs to the user. Programs do not (and should not) have the ability to create records the user can't delete. Do you mean something else?

Resources