how to add birthday from my application to my phone address book - iphone

I have a task to develop the application related to address and access the birthdate from it. And if the user has to exists in the address then i can enter it manually from my application to address book.
I have to develop the application related to address book. From address book i have to get name,phone no,email, and birthday. so i can easily get it on my application. But for get i have set all thing from address book. But i also have to give facility to add the contact detail as above given field. and i can not find easily that how to add birthday in address book i have search a lot but i cant found it,
So,please help me and provide some sample code for it.

int recordId=123 //recordId in address book for record we want to update
//save birthday to address book
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABAddressBookGetPersonWithRecordID (addressBook,recordId);
CFErrorRef error = NULL;
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"dd.MM.yyyy"];
//don't set year in address book (yyyy=1604)
NSDate *date = [formatter dateFromString:[NSString stringWithFormat:#"%#.1604",#"29.03"]];
[formatter release];
ABRecordSetValue(person, kABPersonBirthdayProperty,(CFDateRef)date, &error);
ABAddressBookSave (addressBook,&error);
CFRelease(addressBook);
Don't forget to import AddressBook/AddressBook.h file and add AddressBook.framework.

There is a demo app in Apple's code library called QuickContacts. You can download it and refer it. In that demo app there is a functionality where in you can create a new contact and it will save that contact in your iPhone's contacts.
Now, you can modify that controller and customize it as per your requirements. I didn't go down into the tiniest detail but I guess this would help you. You can download that demo app called QuickContacts from here.
You might have to work a little bit but I hope it helps!

Related

how to add facebook's friends into iphone's address book

I'm new in iPhone development. I want to add facebook's friends name into iPhone's address book.
I can get get facebook's friend list from the facebook using facebook's sdk.framework.
Can someone help me to insert this friends name into iPhone address book?
You need to read Adress book programing from here
And for inserting contact: idea is -
You need make object of address book ABAddressBookRef addressBook = ABAddressBookCreate();
then create a record like this ABRecordRef person = ABPersonCreate();
then set some property like this
ABRecordSetValue(person, kABPersonFirstNameProperty, CFSTR(fbUserName), &anError);
fbUserName is the name of your friend getting by fbGraph api.
then you need to insert this record in address book ABAddressBookAddRecord();
then save the changes. ABAddressBookSave();
at last
CFRelease(addressBook);

AddressBook kABPersonEmailProperty returns nil for some contacts

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!

Currency Conversion and display fetched from Server

I am fetching the in app purchase items for my app from my web server.the web-server gives the product title, description and price...
Currently i am displaying the each product using the product title,description and price.Currently i am showing the currency in $.
Now i am having the doubt that , can i display the prices as such?when i referred some URL, it seems that prices needs to be localized.
So do i need to display the prices localized which is fetched from my-server? please let me know how should i proceed?
Thanks a lot for stopping by..
Yes, you should show localized prices.
From App Store Quick Reference: Getting Started with In-App Purchase on iOS and OS X Lion:
Since your application may be available in App Stores with a region specific currency and
language, your item’s localized description and pricing information should be pulled from the
App Store via StoreKit’s products request API. You’ll use the information returned from the
products request to populate the user interface you present to the customer for item selection
and purchase
The product request API from StoreKit is pretty straightforward, it returns a ProductResponse, which contains an SKProduct, which includes both the price and the priceLocale. Per the SKProduct Class Reference, your code to format the price in the current local should be something like:
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:product.priceLocale];
NSString *formattedString = [numberFormatter stringFromNumber:product.price];

iOS iTunes store country

i am wondering if there is a solution to find out, in which country the user downloaded an application.
For example: app x has been downloaded in USA when the user opens up the app, the app will check in which country it was downloaded. In this example the the return would be "USA"
Does any one hase an idea on how to solve this?
If you have any In-App Purchases available, you can read the locale from the SKProduct. As a fallback, use the device's locale.
NSLocale *locale;
SKProduct *baseProduct = nil; // replace as applicable
if (baseProduct) {
locale = baseProduct.priceLocale; // from the user's credit card on iTunes
} else {
locale = [NSLocale currentLocale]; // from user preferences
}
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
NSLog(#"Two-letter country code: %#", countryCode);
There might be a good enough correlation between the iTunes store country and the locale a user sets. This depends on your needs - if this does not suffice, I don't think there is a way to know which actual store an app was downloaded from.
To retrieve that locale, you could use:
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
Hope this is sufficient for your needs.
It's not possible to check "which" App Store an app was downloaded.
If you need to do anything location-based, you should look at CLLocation to obtain a user's current location, however it may seem intrusive for the app to ask a user for their location if it's not apparent why it would need the location.
You could also check for the language on a users device, such as en_gb for Britain, dk for Denmark, en_ca for Canada, etc. While this doesn't completely cover when people in some countries have set the language to something else than the countries native language, it's better than nothing.
SKStoreFront, introduced in iOS 13 SDK seems to do the job.
Swift
if let storefront = SKPaymentQueue.default().storefront {
print(storefront.countryCode) // Returns an Alpha-3 country code (USA, GBR etc.)
}
Obj C
[SKPaymentQueue defaultQueue].storefront.countryCode; // Returns an Alpha-3 country code (USA, GBR etc.)
You should be able to access the SKStoreFront instance by adding the StoreKit framework to your project, even if your app does not offer any purchases.

Accessing native iPhone addressbook database and performing add and delete contacts?

In my application I need to implement the address book which should contains the native addressbook details, and the user should be able to add and delete from the address book and it should be updated in the native iphone addressbook.
I read somewhere that the iphone native address book database is accesible. In documentation also I saw that addContact and Delete API's are exposed to addressbook.
Can anyone please tell me how can I access the native AddressBook of the iphone, and..
how to add and delete contacts from the address book?
Can anyone post the sample code for this?
You need to use ABRecords and ABAddressBook. For example, adding can be done:
#import <AddressBook/AddressBook.h>
...
ABRecordRef record = ABPersonCreate();
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordSetValue(record, kABPersonFirstNameProperty, CFSTR("Kevin"), NULL);
ABRecordSetValue(record, kABPersonLastNameProperty, CFSTR("Sylvestre"), NULL);
ABAddressBookAddRecord(addressBook, record, NULL);
ABAddressBookSave(addressBook, NULL);
It is important that you add the AddressBook.Framework to your project (right click on 'Frameworks' > 'Add' > 'Existing Frameworks'). The documentation should give you enough to figure out how to remove, etc.